當運行on Rails的5.1集成規格的javascript_pack_tag幫手編譯包/生成路徑public/packs/application.js
沒有路由匹配[GET] 「/packs/application.js」 的Rails 5.1
然而,bin/rails assets:precompile
的application.js文件將編譯您的包與生產配置,其中包括消化。因此無法找到該文件。
當運行on Rails的5.1集成規格的javascript_pack_tag幫手編譯包/生成路徑public/packs/application.js
沒有路由匹配[GET] 「/packs/application.js」 的Rails 5.1
然而,bin/rails assets:precompile
的application.js文件將編譯您的包與生產配置,其中包括消化。因此無法找到該文件。
編譯包/ application.js中爲public/packs/application.js
通過指定開發環境:運行您的集成功能之前
RAILS_ENV=development bin/webpack
運行此任務。
這裏是我的設置來運行本地測試環境的WebPack-dev的服務器使用了Rails 5.1 webpacker寶石時:
在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
在持續集成環境中禁用webpa ck-dev-server,而在執行測試套件之前,您可以運行RAILS_ENV=development bin/webpack
。
感謝此Github comment。
這是我的地方共建的命令列表,以支持所有的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