Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
11 changes: 4 additions & 7 deletions lib/install/bin/webpack
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
33 changes: 27 additions & 6 deletions lib/webpacker/webpack_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down