Class: Shakapacker::WebpackRunner

Inherits:
Runner
  • Object
show all
Defined in:
lib/shakapacker/webpack_runner.rb

Constant Summary collapse

WEBPACK_COMMANDS =
[
  "help",
  "h",
  "--help",
  "-h",
  "version",
  "v",
  "--version",
  "-v",
  "info",
  "i"
].freeze

Instance Method Summary collapse

Methods inherited from Runner

#initialize, #package_json, run

Constructor Details

This class inherits a constructor from Shakapacker::Runner

Instance Method Details

#runObject



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
# File 'lib/shakapacker/webpack_runner.rb', line 19

def run
  env = Shakapacker::Compiler.env
  env["SHAKAPACKER_CONFIG"] = @shakapacker_config
  env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""

  cmd = build_cmd

  if @argv.delete("--debug-shakapacker")
    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