2017-02-27 46 views

回答

2

編譯包/ application.js中爲public/packs/application.js通過指定開發環境:運行您的集成功能之前

RAILS_ENV=development bin/webpack 

運行此任務。

0

這裏是我的設置來運行本地測試環境的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

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 
相關問題