-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-dev-server
executable file
·25 lines (18 loc) · 1.04 KB
/
webpack-dev-server
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
#!/usr/bin/env ruby
ENV['RAILS_ENV'] ||= 'development'
RAILS_ENV = ENV['RAILS_ENV']
ENV['NODE_ENV'] ||= RAILS_ENV
NODE_ENV = ENV['NODE_ENV']
APP_PATH = File.expand_path('../', __dir__)
SET_NODE_PATH = "NODE_PATH=#{APP_PATH}/node_modules"
WEBPACKER_BIN = "./node_modules/.bin/webpack-dev-server"
WEBPACK_CONFIG = "#{APP_PATH}/config/webpack/#{NODE_ENV}.js"
# Warn the user if the configuration is not set
RAILS_ENV_CONFIG = File.join("config", "environments", "#{RAILS_ENV}.rb")
# Look into the environment file for a non-commented variable declaration
unless File.foreach(File.join(APP_PATH, RAILS_ENV_CONFIG)).detect { |line| line.match(/^\s*[^#]*config\.x\.webpacker\[\:dev_server_host\].*=/) }
puts "Warning: if you want to use webpack-dev-server, you need to tell Webpacker to serve asset packs from it. Please set config.x.webpacker[:dev_server_host] in #{RAILS_ENV_CONFIG}.\n\n"
end
Dir.chdir(APP_PATH) do
exec "#{SET_NODE_PATH} #{WEBPACKER_BIN} --config #{WEBPACK_CONFIG} --content-base #{APP_PATH}/public/packs #{ARGV.join(" ")}"
end