Skip to content

Commit f0d2913

Browse files
Feature/webpack runner rework (#3144)
* Ordering requires in bin/webpack * Allow usage of Webpack default commands * Updating the readme for new options
1 parent b4d5995 commit f0d2913

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,19 @@ If you want to use live code reloading, or you have enough JavaScript that on-de
211211
./bin/webpack-dev-server
212212
213213
# watcher
214-
./bin/webpack --watch --colors --progress
214+
./bin/webpack --watch --progress
215215
216216
# standalone build
217-
./bin/webpack
217+
./bin/webpack --progress
218+
219+
# Help
220+
./bin/webpack help
221+
222+
# Version
223+
./bin/webpack version
224+
225+
# Info
226+
./bin/webpack info
218227
```
219228

220229
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`

lib/install/bin/webpack

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#!/usr/bin/env ruby
22

3-
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4-
ENV["NODE_ENV"] ||= "development"
5-
63
require "pathname"
7-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8-
Pathname.new(__FILE__).realpath)
9-
104
require "bundler/setup"
11-
125
require "webpacker"
136
require "webpacker/webpack_runner"
147

8+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
9+
ENV["NODE_ENV"] ||= "development"
10+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
11+
1512
APP_ROOT = File.expand_path("..", __dir__)
1613
Dir.chdir(APP_ROOT) do
1714
Webpacker::WebpackRunner.run(ARGV)

lib/webpacker/webpack_runner.rb

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33

44
module Webpacker
55
class WebpackRunner < Webpacker::Runner
6+
WEBPACK_COMMANDS = [
7+
"help",
8+
"h",
9+
"--help",
10+
"-h",
11+
"version",
12+
"v",
13+
"--version",
14+
"-v",
15+
"info",
16+
"i"
17+
].freeze
18+
619
def run
720
env = Webpacker::Compiler.env
821
env["WEBPACKER_CONFIG"] = @webpacker_config
@@ -13,17 +26,25 @@ def run
1326
["yarn", "webpack"]
1427
end
1528

16-
if @argv.include?("--debug-webpacker")
17-
cmd = [ "node", "--inspect-brk"] + cmd
29+
if @argv.delete "--debug-webpacker"
30+
cmd = ["node", "--inspect-brk"] + cmd
1831
@argv.delete "--debug-webpacker"
1932
end
2033

21-
if @argv.include?("--trace-deprecation")
22-
cmd = [ "node", "--trace-deprecation"] + cmd
23-
@argv.delete "--trace-deprecation"
34+
if @argv.delete "--trace-deprecation"
35+
cmd = ["node", "--trace-deprecation"] + cmd
36+
end
37+
38+
if @argv.delete "--no-deprecation"
39+
cmd = ["node", "--no-deprecation"] + cmd
40+
end
41+
42+
# Webpack commands are not compatible with --config option.
43+
if (@argv & WEBPACK_COMMANDS).empty?
44+
cmd += ["--config", @webpack_config]
2445
end
2546

26-
cmd += ["--config", @webpack_config] + @argv
47+
cmd += @argv
2748

2849
Dir.chdir(@app_path) do
2950
Kernel.exec env, *cmd

0 commit comments

Comments
 (0)