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:precompilestep 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
APP_ROOT = File.expand_path('..', __dir__)
exec "yarnpkg", *ARGV
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
bin/yarnalso needs to be marked as executable in git so that it can be run during the precompile stage.
git add --chmod=+x bin/yarn
git commit -m "Add bin/yarn"
Then your next deploy should correctly run Yarn to install the packages at the beginning of the assets precompile.