闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

  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_FILE = File.join(APP_PATH, "config/webpacker.yml")
  11. NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
  12. WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/development.js")
  13. def args(key)
  14. index = ARGV.index(key)
  15. index ? ARGV[index + 1] : nil
  16. end
  17. begin
  18. dev_server = YAML.load_file(CONFIG_FILE)["development"]["dev_server"]
  19. DEV_SERVER_HOST = "http#{"s" if args('--https') || dev_server["https"]}://#{dev_server["host"]}:#{args('--port') || dev_server["port"]}"
  20. rescue Errno::ENOENT, NoMethodError
  21. puts "Webpack dev_server configuration not found in #{CONFIG_FILE}."
  22. puts "Please run bundle exec rails webpacker:install to install webpacker"
  23. exit!
  24. end
  25. newenv = {
  26. "NODE_PATH" => NODE_MODULES_PATH.shellescape,
  27. "ASSET_HOST" => DEV_SERVER_HOST.shellescape
  28. }.freeze
  29. cmdline = ["yarn", "run", "webpack-dev-server", "--", "--progress", "--color", "--config", WEBPACK_CONFIG] + ARGV
  30. Dir.chdir(APP_PATH) do
  31. exec newenv, *cmdline
  32. end