Skip to content

Commit

Permalink
fix: hmr: false doesn't disable Hot Module Replacement
Browse files Browse the repository at this point in the history
* webpacker-dev-server >= 4 enables HMR by default, so explicitly disable when `hmr: false`
  • Loading branch information
thedanbob committed Dec 24, 2023
1 parent 0f89275 commit bb54132
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _Please add entries here for your pull requests that are not yet released._
- Recommend `server` option instead of deprecated `https` option when `--https` is provided [PR 380](https://github.com/shakacode/shakapacker/pull/380) by [G-Rath](https://github.com/g-rath)
- Recompile assets on asset host change [PR 364](https://github.com/shakacode/shakapacker/pull/364) by [ahangarha](https://github.com/ahangarha).
- Add deprecation warning for `https` option in `shakapacker.yml` (use `server: 'https'` instead) [PR 382](https://github.com/shakacode/shakapacker/pull/382) by [G-Rath](https://github.com/g-rath).
- Disable Hot Module Replacement in `webpack-dev-server` when `hmr: false` [PR 392](https://github.com/shakacode/shakapacker/pull/392) by [thedanbob](https://github.com/thedanbob).

## [v7.1.0] - September 30, 2023

Expand Down
5 changes: 3 additions & 2 deletions lib/shakapacker/dev_server_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def execute_cmd
cmd += ["--config", @webpack_config]
cmd += ["--progress", "--color"] if @pretty

cmd += ["--hot"] if @hot
cmd += ["only"] if @hot == "only"
# Default behavior of webpack-dev-server is @hot = true
cmd += ["--hot", "only"] if @hot == "only"
cmd += ["--no-hot"] if !@hot

cmd += @argv

Expand Down
20 changes: 10 additions & 10 deletions spec/backward_compatibility_specs/dev_server_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
hmr?: true
)
)

Expand All @@ -70,23 +70,23 @@
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
hmr?: true
)
)

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

it "supports hot module reloading" do
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot"])
it "supports disabling hot module reloading" do
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"])

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "http",
hmr?: true
hmr?: false
)
)

Expand Down Expand Up @@ -136,7 +136,7 @@
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
hmr?: true
)
)

Expand All @@ -152,23 +152,23 @@
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
hmr?: true
)
)

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

it "supports hot module reloading" do
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot"]
it "supports disabling hot module reloading" do
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "http",
hmr?: true
hmr?: false
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ development:
host: localhost
port: 3035
public: localhost:3035
hmr: false
hmr: true
overlay: true
disable_host_check: true
use_local_ip: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ development:
host: localhost
port: 3035
public: localhost:3035
hmr: false
hmr: true
# If HMR is on, CSS will by inlined by delivering it as part of the script payload via style-loader. Be sure
# that you add style-loader to your project dependencies.
#
Expand Down
20 changes: 10 additions & 10 deletions spec/shakapacker/dev_server_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
hmr?: true
)
)

Expand All @@ -69,23 +69,23 @@
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
hmr?: true
)
)

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

it "supports hot module reloading" do
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot"])
it "supports disabling hot module reloading" do
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"])

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "http",
hmr?: true
hmr?: false
)
)

Expand Down Expand Up @@ -134,7 +134,7 @@
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
hmr?: true
)
)

Expand All @@ -150,23 +150,23 @@
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
hmr?: true
)
)

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

it "supports hot module reloading" do
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot"]
it "supports disabling hot module reloading" do
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "http",
hmr?: true
hmr?: false
)
)

Expand Down
2 changes: 1 addition & 1 deletion spec/shakapacker/test_app/config/shakapacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ development:
host: localhost
port: 3035
public: localhost:3035
hmr: false
hmr: true
overlay: true
disable_host_check: true
use_local_ip: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ development:
host: localhost
port: 3035
public: localhost:3035
hmr: false
hmr: true
# If HMR is on, CSS will by inlined by delivering it as part of the script payload via style-loader. Be sure
# that you add style-loader to your project dependencies.
#
Expand Down

0 comments on commit bb54132

Please sign in to comment.