webpack-dev-server 1011 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env ruby
  2. $stdout.sync = true
  3. require "shellwords"
  4. require "yaml"
  5. ENV["RAILS_ENV"] ||= "development"
  6. RAILS_ENV = ENV["RAILS_ENV"]
  7. ENV["NODE_ENV"] ||= RAILS_ENV
  8. NODE_ENV = ENV["NODE_ENV"]
  9. APP_PATH = File.expand_path("../", __dir__)
  10. CONFIG_PATH = File.join(APP_PATH, "config/webpack/paths.yml")
  11. begin
  12. paths = YAML.load(File.read(CONFIG_PATH))[NODE_ENV]
  13. NODE_MODULES_PATH = File.join(APP_PATH.shellescape, paths["node_modules"])
  14. WEBPACK_CONFIG_PATH = File.join(APP_PATH.shellescape, paths["config"])
  15. WEBPACK_BIN = "#{NODE_MODULES_PATH}/.bin/webpack-dev-server"
  16. DEV_SERVER_CONFIG = "#{WEBPACK_CONFIG_PATH}/development.server.js"
  17. rescue Errno::ENOENT, NoMethodError
  18. puts "Configuration not found in config/webpacker/paths.yml."
  19. puts "Please run bundle exec rails webpacker:install to install webpacker"
  20. exit!
  21. end
  22. Dir.chdir(APP_PATH) do
  23. exec "NODE_PATH=#{NODE_MODULES_PATH} #{WEBPACK_BIN} --progress --color " \
  24. "--config #{DEV_SERVER_CONFIG} #{ARGV.join(" ")}"
  25. end