At a client, we’re converting all projects (i.e., sites, services, libraries) from npm
to yarn
. Mostly for the speed (as it uses the internal cache).
Step by step guide
- Install yarn in your local environment * https://yarnpkg.com/lang/en/docs/install/
- Run
yarn install
* This will create ayarn.lock
file * Add that file to the repo:git add yarn.lock
- Modify Dockerfile
* Install yarn (in the Dockerfile). Idea: shortcut this execution with
yarn --version
in case it is installed * Configure the PATH variable (ENV PATH …) *ADD yarn.lock
* Replacenpm install
withyarn install
- Modify pipeline
* See example (below)
*
install_yarn
. Idea: shortcut this execution withyarn --version
in case it is installed * Replacenpm install
withyarn install
- Test it
Jenkins
Build step: execute shell
function install_yarn {
yarn --version || curl -o- -L https://yarnpkg.com/install.sh | bash
export PATH="$HOME/.yarn/bin:$PATH"
}
install_yarn
yarn install