Jace Browning
Jace Browning

Reputation: 12662

How do I cache global NPM packages on Travis CI?

Locally installed packages are cached via:

# .travis.yml
...
cache:
  directories:
  - node_modules
...

But how do I cache globally installed packages ($ npm install -g <...>) to speed up my builds?

Upvotes: 13

Views: 1778

Answers (1)

tandrewnichols
tandrewnichols

Reputation: 3466

This is how I did it:

cache:
  directories:
    # Replace "grunt-cli" with whatever global binary you're using
    - $(npm config get prefix)/bin/grunt-cli

EDIT:

As was pointed out in the comments, $(npm config get prefix)/bin contains symlinks to other code. This is untested but would probably work: $(npm config get prefix)/lib/node_modules. That should cache all globally installed modules.

Upvotes: 12

Related Questions