diff --git a/CHANGELOG.md b/CHANGELOG.md index ce68ea28e..7a3de443a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/shakapacker/dev_server_runner.rb b/lib/shakapacker/dev_server_runner.rb index dc0d55806..c479a2ecc 100644 --- a/lib/shakapacker/dev_server_runner.rb +++ b/lib/shakapacker/dev_server_runner.rb @@ -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 diff --git a/spec/backward_compatibility_specs/dev_server_runner_spec.rb b/spec/backward_compatibility_specs/dev_server_runner_spec.rb index e31a674b4..6bb300e00 100644 --- a/spec/backward_compatibility_specs/dev_server_runner_spec.rb +++ b/spec/backward_compatibility_specs/dev_server_runner_spec.rb @@ -26,7 +26,7 @@ require "package_json" it "uses the expected package manager", unless: fallback_manager == "yarn_classic" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]) + cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]) manager_name = fallback_manager.split("_")[0] @@ -34,19 +34,19 @@ end it "runs the command using the manager" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]) + cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]) verify_command(cmd) end it "passes on arguments" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]) + cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot", "--quiet"]) verify_command(cmd, argv: (["--quiet"])) end it "does not automatically pass the --https flag" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]) + 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( @@ -62,7 +62,7 @@ end it "supports the https flag" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]) + cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot", "--https"]) allow(Shakapacker::DevServer).to receive(:new).and_return( double( @@ -94,7 +94,7 @@ end it "accepts environment variables" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]) + cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]) env = Webpacker::Compiler.env.dup # ENV["WEBPACKER_CONFIG"] is the interface and env["SHAKAPACKER_CONFIG"] is internal @@ -110,25 +110,25 @@ with_use_package_json_gem(enabled: false) it "supports running via node modules" do - cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"] + cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"] verify_command(cmd, use_node_modules: true) end it "supports running via yarn" do - cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"] + cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"] verify_command(cmd, use_node_modules: false) end it "passes on arguments" do - cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"] + cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot", "--quiet"] verify_command(cmd, argv: (["--quiet"])) end it "does not automatically pass the --https flag" do - cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"] + 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( @@ -144,7 +144,7 @@ end it "supports the https flag" do - cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"] + cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot", "--https"] allow(Shakapacker::DevServer).to receive(:new).and_return( double( @@ -176,7 +176,7 @@ end it "accepts environment variables" do - cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"] + cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"] env = Webpacker::Compiler.env.dup # ENV["WEBPACKER_CONFIG"] is the interface and env["SHAKAPACKER_CONFIG"] is internal diff --git a/spec/shakapacker/dev_server_runner_spec.rb b/spec/shakapacker/dev_server_runner_spec.rb index 0fe3095a6..322a5679b 100644 --- a/spec/shakapacker/dev_server_runner_spec.rb +++ b/spec/shakapacker/dev_server_runner_spec.rb @@ -25,7 +25,7 @@ require "package_json" it "uses the expected package manager", unless: fallback_manager == "yarn_classic" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]) + cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]) manager_name = fallback_manager.split("_")[0] @@ -33,19 +33,19 @@ end it "runs the command using the manager" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]) + cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]) verify_command(cmd) end it "passes on arguments" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]) + cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot", "--quiet"]) verify_command(cmd, argv: (["--quiet"])) end it "does not automatically pass the --https flag" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]) + 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( @@ -61,7 +61,7 @@ end it "supports the https flag" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]) + cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot", "--https"]) allow(Shakapacker::DevServer).to receive(:new).and_return( double( @@ -93,7 +93,7 @@ end it "accepts environment variables" do - cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]) + cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]) env = Shakapacker::Compiler.env.dup ENV["SHAKAPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/shakapacker_other_location.yml" @@ -108,25 +108,25 @@ with_use_package_json_gem(enabled: false) it "supports running via node modules" do - cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"] + cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"] verify_command(cmd, use_node_modules: true) end it "supports running via yarn" do - cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"] + cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"] verify_command(cmd, use_node_modules: false) end it "passes on arguments" do - cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"] + cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot", "--quiet"] verify_command(cmd, argv: (["--quiet"])) end it "does not automatically pass the --https flag" do - cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"] + 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( @@ -142,7 +142,7 @@ end it "supports the https flag" do - cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"] + cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot", "--https"] allow(Shakapacker::DevServer).to receive(:new).and_return( double( @@ -190,7 +190,7 @@ end it "accepts environment variables" do - cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"] + cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"] env = Shakapacker::Compiler.env.dup ENV["SHAKAPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/shakapacker_other_location.yml"