没有路线匹配[GET]" /packs/application.js" Rails 5.1

时间:2017-02-27 12:28:59

标签: ruby-on-rails webpack

在Rails 5.1上运行集成规范时,javascript_pack_tag帮助程序为public/packs/application.js

中的已编译包/ application.js文件生成路径

但是,bin/rails assets:precompile将使用生产配置编译您的包,其中包括摘要。因此无法找到该文件。

3 个答案:

答案 0 :(得分:4)

要将包/ application.js编译为public/packs/application.js,请通过以下方式指定开发环境:

RAILS_ENV=development bin/webpack

在运行集成规范之前运行此任务。

答案 1 :(得分:0)

这是我在使用Rails 5.1 webpacker gem时在本地测试环境中运行webpack-dev-server的设置:

config/environments/test.rb中,添加:

unless ENV['CI'] == 'true'
  config.x.webpacker[:dev_server_host] = "http://localhost:8080"
end

然后在spec/rails_helper.rb或您的测试设置中添加:

config.add_setting :webpack_dev_server_pid

config.before(:suite) do
  unless ENV['CI'] == 'true'
    RSpec.configuration.webpack_dev_server_pid = fork do
      puts "Child process starting webpack-dev-server"
      webpack_dev_server_cmd = [
        "#{Rails.root}/node_modules/.bin/webpack-dev-server",
        "--config #{Rails.root}/config/webpack/development.js",
        "--content-base #{Rails.root}/public/packs",
        "--quiet"
      ].join(" ")
      exec(webpack_dev_server_cmd)
    end
  end
end

config.after(:suite) do
  unless ENV['CI'] == 'true'
    puts "Killing webpack-dev-server"
    Process.kill("HUP",RSpec.configuration.webpack_dev_server_pid)
    begin
      Timeout.timeout(2) do
        Process.wait(RSpec.configuration.webpack_dev_server_pid,0)
      end
    rescue => Timeout::Error
      Process.kill(9,RSpec.configuration.webpack_dev_server_pid)
    ensure
      RSpec.configuration.webpack_dev_server_pid = nil
    end
  end
end

此设置允许您在持续集成环境中设置CI=true以禁用webpack-dev服务器,您可以在执行测试套件之前运行RAILS_ENV=development bin/webpack

相信这个Github comment

答案 2 :(得分:0)

这是我支持所有Rails 5.1更新的本地构建命令列表:

brew update 
brew install yarn 
./bin/yarn install 
./bin/yarn add webpack 
./bin/webpack-watcher 
bundle exec rake db:create 
bundle exec rake db:migrate