From 1954eeaffc183e4b24a0282c45d0a3a0ff6ab7a2 Mon Sep 17 00:00:00 2001 From: Guillaume Briday Date: Sat, 28 Aug 2021 13:29:05 +0200 Subject: [PATCH 1/3] Ordering requires in bin/webpack --- lib/install/bin/webpack | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/install/bin/webpack b/lib/install/bin/webpack index 1031168d0..2e30da830 100755 --- a/lib/install/bin/webpack +++ b/lib/install/bin/webpack @@ -1,17 +1,14 @@ #!/usr/bin/env ruby -ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" -ENV["NODE_ENV"] ||= "development" - require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - require "bundler/setup" - require "webpacker" require "webpacker/webpack_runner" +ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" +ENV["NODE_ENV"] ||= "development" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath) + APP_ROOT = File.expand_path("..", __dir__) Dir.chdir(APP_ROOT) do Webpacker::WebpackRunner.run(ARGV) From 414f9c53eb2481a3409558be1a6db31f3bdce815 Mon Sep 17 00:00:00 2001 From: Guillaume Briday Date: Sat, 28 Aug 2021 13:29:38 +0200 Subject: [PATCH 2/3] Allow usage of Webpack default commands --- lib/webpacker/webpack_runner.rb | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/webpacker/webpack_runner.rb b/lib/webpacker/webpack_runner.rb index 1999774a3..8f83dc334 100644 --- a/lib/webpacker/webpack_runner.rb +++ b/lib/webpacker/webpack_runner.rb @@ -3,6 +3,19 @@ module Webpacker class WebpackRunner < Webpacker::Runner + WEBPACK_COMMANDS = [ + "help", + "h", + "--help", + "-h", + "version", + "v", + "--version", + "-v", + "info", + "i" + ].freeze + def run env = Webpacker::Compiler.env env["WEBPACKER_CONFIG"] = @webpacker_config @@ -13,17 +26,25 @@ def run ["yarn", "webpack"] end - if @argv.include?("--debug-webpacker") - cmd = [ "node", "--inspect-brk"] + cmd + if @argv.delete "--debug-webpacker" + cmd = ["node", "--inspect-brk"] + cmd @argv.delete "--debug-webpacker" end - if @argv.include?("--trace-deprecation") - cmd = [ "node", "--trace-deprecation"] + cmd - @argv.delete "--trace-deprecation" + if @argv.delete "--trace-deprecation" + cmd = ["node", "--trace-deprecation"] + cmd + end + + if @argv.delete "--no-deprecation" + cmd = ["node", "--no-deprecation"] + cmd + end + + # Webpack commands are not compatible with --config option. + if (@argv & WEBPACK_COMMANDS).empty? + cmd += ["--config", @webpack_config] end - cmd += ["--config", @webpack_config] + @argv + cmd += @argv Dir.chdir(@app_path) do Kernel.exec env, *cmd From 65ccd6e22608db173f8b04f7688cd9229a3cc966 Mon Sep 17 00:00:00 2001 From: Guillaume Briday Date: Sun, 29 Aug 2021 10:26:09 +0200 Subject: [PATCH 3/3] Updating the readme for new options --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a34c4c8e1..5dcb04f0b 100644 --- a/README.md +++ b/README.md @@ -211,10 +211,19 @@ If you want to use live code reloading, or you have enough JavaScript that on-de ./bin/webpack-dev-server # watcher -./bin/webpack --watch --colors --progress +./bin/webpack --watch --progress # standalone build -./bin/webpack +./bin/webpack --progress + +# Help +./bin/webpack help + +# Version +./bin/webpack version + +# Info +./bin/webpack info ``` Once you start this webpack development server, Webpacker will automatically start proxying all webpack asset requests to this server. When you stop this server, Rails will detect that it's not running and Rails will revert back to on-demand compilation _if_ you have the `compile` option set to true in your `config/webpacker.yml`