capistrano-npm is a Capistrano extension that will let you run npm during your deploy process.
- Install the Gem
gem install capistrano-npm
Or if you're using Bundler, add it to your Gemfile
:
gem 'capistrano-npm'
- Add to
Capfile
orconfig/deploy.rb
:
require 'capistrano/npm'
Add the task to your deploy.rb
:
after 'deploy:finalize_update', 'npm:install'
And npm install
will be run in your in your latest_release
path on deploy:finalize_update
.
There's currently no way to specify a path other than the default latest_releast
where npm installs. This will be fixed in a future version.
Ideally when using npm, you should add node_modules
to your .gitignore
file to keep them out of your repository.
Since npm install
does not guarantee that you will get the same package versions when deploying, you should use npm shrinkwrap
(https://npmjs.org/doc/shrinkwrap.html) first.
Running npm shrinkwrap
will created a npm-shrinkwrap.json
file that locks down the dependency versions. Check this file into your repository.
Now when deploying, npm install
will detect the npm-shrinkwrap.json
file and use that to install the packages.
npm:install
: Runsnpm install
.
This extension also adds the npm
command as a Capistrano dependency. Meaning when you run cap deploy:check
, it will make sure the npm
command exists.
npm_path
: Path to npm bin on the remote server. Defaults to justnpm
as its assumed to be in your$PATH
.npm_options
: Options fornpm
command. Defaults to--production --silent
to avoid installing dev dependencies.