diff --git a/CHANGELOG.md b/CHANGELOG.md index 7100d9b2d..8cffeea57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,8 +26,9 @@ environment.loaders.append('nodeModules', nodeModules) - Simple webpack config - Removed integration installers - Splitchunks enabled by default -- CSS extraction enabled by default +- CSS extraction enabled by default, except when devServer is configured and running - Optional CSS support +- Renamed DevServer.running? to DevServer.configured_and_running? ## [[5.4.0]](https://github.com/rails/webpacker/compare/v5.3.0...v5.4.0) - 2021-05-18 diff --git a/lib/webpacker/dev_server.rb b/lib/webpacker/dev_server.rb index c38a2f72e..f3f0eaa9f 100644 --- a/lib/webpacker/dev_server.rb +++ b/lib/webpacker/dev_server.rb @@ -11,7 +11,7 @@ def initialize(config) @config = config end - def running? + def configured_and_running? if config.dev_server.present? Socket.tcp(host, port, connect_timeout: connect_timeout).close true diff --git a/lib/webpacker/dev_server_proxy.rb b/lib/webpacker/dev_server_proxy.rb index 577a08ff2..ba663ddb1 100644 --- a/lib/webpacker/dev_server_proxy.rb +++ b/lib/webpacker/dev_server_proxy.rb @@ -10,7 +10,7 @@ def initialize(app = nil, opts = {}) end def perform_request(env) - if env["PATH_INFO"].start_with?("/#{public_output_uri_path}") && dev_server.running? + if env["PATH_INFO"].start_with?("/#{public_output_uri_path}") && dev_server.configured_and_running? env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = dev_server.host env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = dev_server.port.to_s diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb index b1a56c1d9..720bbea18 100644 --- a/lib/webpacker/helper.rb +++ b/lib/webpacker/helper.rb @@ -128,6 +128,10 @@ def preload_pack_asset(name, **options) # # # + # When using the webpack-dev-server, CSS is inlined so HMR can be turned on for CSS, + # including CSS modules + # <%= stylesheet_pack_tag 'calendar', 'map' %> # => nil + # # DO: # # <%= stylesheet_pack_tag 'calendar', 'map' %> @@ -137,7 +141,8 @@ def preload_pack_asset(name, **options) # <%= stylesheet_pack_tag 'calendar' %> # <%= stylesheet_pack_tag 'map' %> def stylesheet_pack_tag(*names, **options) - unless current_webpacker_instance.dev_server.running? + css_extracted = !Webpacker.dev_server.configured_and_running? + if css_extracted stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options) end end diff --git a/lib/webpacker/manifest.rb b/lib/webpacker/manifest.rb index ba5b57f81..232257870 100644 --- a/lib/webpacker/manifest.rb +++ b/lib/webpacker/manifest.rb @@ -51,7 +51,7 @@ def lookup!(name, pack_type = {}) private def compiling? - config.compile? && !dev_server.running? + config.compile? && !dev_server.configured_and_running? end def compile diff --git a/lib/webpacker/railtie.rb b/lib/webpacker/railtie.rb index f2ff72fba..89c4a3507 100644 --- a/lib/webpacker/railtie.rb +++ b/lib/webpacker/railtie.rb @@ -8,7 +8,7 @@ class Webpacker::Engine < ::Rails::Engine config.webpacker = ActiveSupport::OrderedOptions.new initializer "webpacker.proxy" do |app| - insert_middleware = Webpacker.config.dev_server.present? rescue nil + insert_middleware = Webpacker.config.dev_server.present? if insert_middleware app.middleware.insert_before 0, Rails::VERSION::MAJOR >= 5 ? diff --git a/test/dev_server_test.rb b/test/dev_server_test.rb index 28c58d464..3f0a0e328 100644 --- a/test/dev_server_test.rb +++ b/test/dev_server_test.rb @@ -2,7 +2,7 @@ class DevServerTest < Webpacker::Test def test_running? - refute Webpacker.dev_server.running? + refute Webpacker.dev_server.configured_and_running? end def test_host