【问题标题】:What is the proper way to deploy rails 5.x app with capistrano and yarn assets?使用 capistrano 和 yarn 资产部署 rails 5.x 应用程序的正确方法是什么?
【发布时间】:2017-12-19 07:03:18
【问题描述】:

我对所有 js-shenanigans 都还很陌生,以前只是下载我的 js 文件(外部库),一切正常。现在我切换到通过 yarn 安装 js-libraries。无论如何,如果我在.gitignore 中添加或删除/node_modules,我总是会在cap production deploy 上收到此错误

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,将此代码sn-p 添加到我的deploy.rb (picked from this so question):

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

在开发模式下一切正常。

【问题讨论】:

    标签: ruby-on-rails deployment capistrano yarnpkg


    【解决方案1】:

    终于明白了。我必须运行以下代码:

    bundle config --delete bin
    ./bin/rails app:update:bin # or rails app:update:bin
    

    这几乎在 webpacker 描述的最底部here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-29
      • 1970-01-01
      • 2019-04-05
      • 1970-01-01
      • 2019-08-06
      • 1970-01-01
      相关资源
      最近更新 更多