繁体   English   中英

用capistrano和yarn资产部署Rails 5.x应用程序的正确方法是什么?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM