简体   繁体   中英

What is the proper way to deploy rails 5.x app with capistrano and yarn assets?

I'm fairly new to all js-shenanigans, used to simply download my js files (external libraries) and everything worked. Now I switched to installing js-libraries via yarn. No matter, if I add or remove /node_modules from/to .gitignore , I always receive this error upon 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:

I could understand the error if node_modules is added to .gitignore - since my js-files are physically in this directory and I'm ignoring it, it's reasonable, that, ie jquery can't be found. But if I remove node_modules from .gitignore , the error persists.

I tried to add capistrano-yarn to my gemfile, added this code snippet to my 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, {}

But it's more picking in the dark, since I don't actually know what I'm doing.

I'm not able to find any proper tutorial on how to deploy rails app, where assets are managed by yarn. Is there any advice? And could someone explain the logic, where would my production grab the assets from? From node_modules folder? If everyone suggest to add it to .gitignore - where from else then?

Edit: Maybe it's worth noting, that this app was initially a 4.x Rails app and was later updated up to Rails 5.1.2 right now.

Also my application.js looks like this:

//= 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

Everything works fine in development mode.

Finally figured it out. I had to run following code:

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

This was almost at the very bottom of webpacker description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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