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 6ca0bc0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 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
3 changes: 2 additions & 1 deletion lib/webpacker/dev_server_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ 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
cmd += @argv

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

0 comments on commit 6ca0bc0

Please sign in to comment.