forked from shakacode/shakapacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack_runner.rb
68 lines (57 loc) · 1.59 KB
/
webpack_runner.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require "shellwords"
require "shakapacker/runner"
module Shakapacker
class WebpackRunner < Shakapacker::Runner
WEBPACK_COMMANDS = [
"help",
"h",
"--help",
"-h",
"version",
"v",
"--version",
"-v",
"info",
"i"
].freeze
def run
env = Shakapacker::Compiler.env
env["SHAKAPACKER_CONFIG"] = @shakapacker_config
env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""
cmd = if node_modules_bin_exist?
["#{@node_modules_bin_path}/webpack"]
else
["yarn", "webpack"]
end
if @argv.include?("--debug-webpacker")
Shakapacker.puts_deprecation_message(
Shakapacker.short_deprecation_message(
"--debug-webpacker",
"--debug-shakapacker"
)
)
end
if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk"
end
if @argv.delete "--trace-deprecation"
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --trace-deprecation"
end
if @argv.delete "--no-deprecation"
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --no-deprecation"
end
# Webpack commands are not compatible with --config option.
if (@argv & WEBPACK_COMMANDS).empty?
cmd += ["--config", @webpack_config]
end
cmd += @argv
Dir.chdir(@app_path) do
Kernel.exec env, *cmd
end
end
private
def node_modules_bin_exist?
File.exist?("#{@node_modules_bin_path}/webpack")
end
end
end