Of course! We install Yarn by default on all application servers so you can use Webpacker out of the box.
Webpacker adds itself to the
assets:precompile step in Rails so your Webpacker assets will be automatically compiled after the asset pipeline finishes.
These are two separate pipelines and they do not mix in production. You can mistakenly get this to work in development, but this will not work in production. Any assets used in the asset pipeline must be accessible inside the asset pipeline folders.
If you see the following errors, you probably just need to a quick fix to your webpacker install:
Command "webpack" not found
Your app might be missing the yarn binstub. This is required to install node modules before compiling assets. Add the following file to your repo as
bin/yarn#!/usr/bin/env rubyAPP_ROOT = File.expand_path('..', __dir__)Dir.chdir(APP_ROOT) dobeginexec "yarnpkg", *ARGVrescue Errno::ENOENT$stderr.puts "Yarn executable was not detected in the system."$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"exit 1endend
bin/yarn also needs to be marked as executable in git so that it can be run during the precompile stage.
git add --chmod=+x bin/yarngit commit -m "Add bin/yarn"git push
Then your next deploy should correctly run Yarn to install the packages at the beginning of the assets precompile.