Sha256: d7e28485aeb7c08d2452a521aed6b91db749edeb2ae540a9c5c99c5e07ed44d7
Contents?: true
Size: 1.99 KB
Versions: 2
Compression:
Stored size: 1.99 KB
Contents
<%= shebang %> $stdout.sync = true require "shellwords" require "yaml" require "socket" 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__) CONFIG_FILE = File.join(APP_PATH, "config/webpacker.yml") NODE_MODULES_PATH = File.join(APP_PATH, "node_modules") WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js") LISTEN_IP_ADDR = "0.0.0.0" def args(key) index = ARGV.index(key) index ? ARGV[index + 1] : nil end begin dev_server = YAML.load_file(CONFIG_FILE)[RAILS_ENV]["dev_server"] HOSTNAME = args('--host') || dev_server["host"] PORT = args('--port') || dev_server["port"] HTTPS = ARGV.include?('--https') || dev_server["https"] DEV_SERVER_ADDR = "http#{"s" if HTTPS}://#{HOSTNAME}:#{PORT}" rescue Errno::ENOENT, NoMethodError $stdout.puts "Webpack dev_server configuration not found in #{CONFIG_FILE}." $stdout.puts "Please run bundle exec rails webpacker:install to install webpacker" exit! end begin server = TCPServer.new(LISTEN_IP_ADDR, PORT) server.close rescue Errno::EADDRINUSE $stdout.puts "Another program is running on port #{PORT}. Set a new port in #{CONFIG_FILE} for dev_server" exit! end # Delete supplied host and port CLI arguments ["--host", "--port"].each do |arg| ARGV.delete(args(arg)) ARGV.delete(arg) end newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape, "ASSET_HOST" => DEV_SERVER_ADDR.shellescape }.freeze if Gem.win_platform? # Workaround for yarn not playing nicely with path separators cmdline = ["#{NODE_MODULES_PATH}/.bin/webpack-dev-server", "--progress", "--color", "--config", WEBPACK_CONFIG, "--host", LISTEN_IP_ADDR, "--port", PORT.to_s] + ARGV else cmdline = ["yarn", "run", "webpack-dev-server", "--", "--progress", "--color", "--config", WEBPACK_CONFIG, "--host", LISTEN_IP_ADDR, "--port", PORT.to_s] + ARGV end Dir.chdir(APP_PATH) do exec newenv, *cmdline end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
webpacker-react-on-rails-3.0.0.rc.1 | lib/install/bin/webpack-dev-server.tt |
webpacker-react-on-rails-2.0 | lib/install/bin/webpack-dev-server.tt |