![](/img/trans.png)
[英]How to deploy my Webpackered Rails app with Capistrano and Yarn
[英]What is the proper way to deploy rails 5.x app with capistrano and yarn assets?
我對所有的js-shenanigans都是陌生的,曾經只是下載我的js文件(外部庫),並且一切正常。 現在,我切換到通過yarn安裝js庫。 沒關系,如果我在.gitignore
添加或刪除/node_modules
,我總是在cap production deploy
/node_modules
收到此錯誤
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host 92.53.97.113: rake exit status: 1
rake stdout: rake aborted!
Sprockets::FileNotFound: couldn't find file 'jquery' with type 'application/javascript'
Checked in these paths:
如果將node_modules
添加到.gitignore
我可以理解該錯誤-因為我的js文件實際上位於此目錄中,而我卻忽略了它,這是合理的,即找不到jquery。 但是,如果我從.gitignore
刪除node_modules
,該錯誤仍然存在。
我試圖將capistrano-yarn
添加到我的gemfile中,將此代碼段添加到我的deploy.rb
( 從這個問題中選擇 ):
set :nvm_type, :user # or :system, depends on your nvm setup
set :nvm_node, 'v7.10.0'
set :nvm_map_bins, %w{node npm yarn}
set :yarn_target_path, -> { release_path.join('client') } #
set :yarn_flags, '--production --silent --no-progress' # default
set :yarn_roles, :all # default
set :yarn_env_variables, {}
但是,由於我實際上不知道自己在做什么,所以在黑暗中采摘更多。
我找不到任何有關如何部署Rails應用程序的適當教程,該教程中的資產由yarn管理。 有什么建議嗎? 有人可以解釋一下邏輯嗎,我的生產將從何處獲取資產? 從node_modules
文件夾? 如果每個人都建議將其添加到.gitignore
那么從哪里來?
編輯:也許值得注意,該應用程序最初是4.x Rails應用程序,后來又更新到了Rails 5.1.2。
另外我的application.js
看起來像這樣:
//= require jquery
//= require rails-ujs
//= require_tree ../../../vendor/assets/javascripts/front/first/.
//= require front/second/jquery.bxslider
//= require inputmask/dist/jquery.inputmask.bundle
//= require inputmask/dist/inputmask/phone-codes/phone
//= require inputmask/dist/inputmask/phone-codes/phone-be
//= require inputmask/dist/inputmask/phone-codes/phone-ru
//= require front/second/jquery.masonry.min
//= require front/second/js-url.min
//= require_tree ../../../vendor/assets/javascripts/front/third/.
//= require_self
//= require_tree ../../../app/assets/javascripts/front/.
//= require turbolinks
在開發模式下一切正常。
終於想通了。 我必須運行以下代碼:
bundle config --delete bin
./bin/rails app:update:bin # or rails app:update:bin
這幾乎是在webpacker描述的最底部這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.