Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
1. hmr default is false
2. CSS is extracted unless yml file configuredd HMR and running webpack-dev-server
  • Loading branch information
justin808 committed Jun 9, 2021
1 parent 90e80d5 commit 8fbc86f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/install/config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ development:
port: 3035
public: localhost:3035
# Hot Module Replacement updates modules while the application is running without a full reload
hmr: true
hmr: false
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
overlay: true
# Should we use gzip compression?
Expand Down
2 changes: 2 additions & 0 deletions lib/webpacker/dev_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def env_prefix

private
def fetch(key)
return nil unless config.dev_server.present?

ENV["#{env_prefix}_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key])
end

Expand Down
6 changes: 4 additions & 2 deletions lib/webpacker/dev_server_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ def execute_cmd
end

if @argv.include?("--debug-webpacker")
cmd = [ "node", "--inspect-brk"] + cmd
cmd = [ "node", "--inspect-brk", "--trace-warnings" ] + cmd
@argv.delete "--debug-webpacker"
end

cmd += ["--config", @webpack_config]
cmd += ["--progress", "--color"] if @pretty
cmd += ["--hot"] if @hot

# Something about webpack config makes this always mandatory
cmd += ["--hot"]
cmd += @argv

Dir.chdir(@app_path) do
Expand Down
8 changes: 4 additions & 4 deletions lib/webpacker/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ def preload_pack_asset(name, **options)
# <%= stylesheet_pack_tag 'calendar' %>
# <%= stylesheet_pack_tag 'map' %>
def stylesheet_pack_tag(*names, **options)
css_extracted = !Webpacker.dev_server.configured_and_running?
if css_extracted
stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
end
css_inline = Webpacker.dev_server.hmr? && Webpacker.dev_server.configured_and_running?
return "" if css_inline

stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
end

private
Expand Down
7 changes: 5 additions & 2 deletions package/utils/get_style_rule.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint global-require: 0 */

const devServer = require('../dev_server')
const { canProcess, moduleExists, runningWebpackDevServer } = require('./helpers')

const getStyleRule = (test, preprocessors = []) => {
Expand All @@ -10,9 +11,11 @@ const getStyleRule = (test, preprocessors = []) => {
options: { sourceMap: true }
}))

// style-loader is required when using css modules with HMR on the webpack-dev-server
const cssInline = runningWebpackDevServer && devServer.hmr

const use = [
// style-loader is required when using css modules with HMR, so just always use for the dev-server
runningWebpackDevServer ? 'style-loader' : require('mini-css-extract-plugin').loader,
cssInline ? 'style-loader' : require('mini-css-extract-plugin').loader,
{
loader: require.resolve('css-loader'),
options: {
Expand Down
10 changes: 5 additions & 5 deletions test/dev_server_runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ def teardown
end

def test_run_cmd_via_node_modules
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--hot"]

verify_command(cmd, use_node_modules: true)
end

def test_run_cmd_via_yarn
cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--hot"]

verify_command(cmd, use_node_modules: false)
end

def test_run_cmd_argv
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--quiet"]
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--hot", "--quiet"]

verify_command(cmd, argv: ["--quiet"])
end

def test_run_cmd_argv_with_https
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--https"]
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--hot", "--https"]

dev_server = Webpacker::DevServer.new({})
def dev_server.host; "localhost"; end
Expand All @@ -45,7 +45,7 @@ def dev_server.hmr?; false; end
end

def test_environment_variables
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js", "--hot" ]
env = Webpacker::Compiler.env.dup
env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker.yml"
env["WEBPACK_DEV_SERVER"] = "true"
Expand Down

0 comments on commit 8fbc86f

Please sign in to comment.