Using 'yarn' to manage NodeJS modules for assets compilation

Engine Yard now supports the use of 'yarn' as an alternative to 'npm' for the installation of NodeJS modules. yarn has quickly become a major player on the Ruby world, fueled by both its performance and its addition to Rails.

Since release 3.0.23 of our v5 stack, and on v6 and v7 as well, yarn is by default present on all instances, and initial support is present for utilizing it to install the NodeJS modules needed for asset compilation.  If you're using a previous version, then include the custom-packages recipe and have it install sys-apps/yarn version 0.27.5.  Details on how to work with custom Chef recipes can be found here.

To make use of yarn, please follow this process:

  • add a file named ey.yml to the config directory of your application and commit this to the repository. The file should contain the lines below. More information about what can be specified in the ey.yml file can be found here.
  npm:  false
  • since yarn (or npm previously) is used to compile assets, add a before_compile_assets.rb deploy_hook with the code below. This code will be invoked by the deploy process before the assets are compiled, triggering yarn to install the NodeJS modules. Further informantion on using deploy_hooks can be found in the relevant KB article.
run! "cd #{config.release_path} && yarn"

And that's it. On a subsequent deploy, our backend will refrain from running npm when a package.json file is detected, and instead the deploy_hook will invoke yarn. When the assets_compilation stage triggers, the required NodeJS modules will be in place.



Article is closed for comments.