Class: EmberCli::Deploy::DevServer

Inherits:
Object
  • Object
show all
Defined in:
lib/ember_cli/deploy/dev_server.rb

Overview

Serves an Ember application from its Vite development server instead of from the dist directory written by ember build.

The index.html served by the development server refers to its assets (/@vite/client included) with root-relative URLs. Rails serves the document from its own origin, so those URLs are rewritten to absolute URLs pointing at the development server. Loading them from there means the Vite client opens its HMR WebSocket against the development server directly, without Rails proxying it.

Constant Summary collapse

ROOT_RELATIVE_URL =
%r{(\s)(src|href)=(["'])/(?!/)}i

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ DevServer

Returns a new instance of DevServer.



18
19
20
# File 'lib/ember_cli/deploy/dev_server.rb', line 18

def initialize(app)
  @app = app
end

Instance Method Details

#index_htmlObject



30
31
32
# File 'lib/ember_cli/deploy/dev_server.rb', line 30

def index_html
  rewrite_root_relative_urls(dev_server.index_html)
end

#mountable?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ember_cli/deploy/dev_server.rb', line 22

def mountable?
  true
end

#to_rackObject



26
27
28
# File 'lib/ember_cli/deploy/dev_server.rb', line 26

def to_rack
  DevServerProxy.new(app)
end