LoginSignup
2

More than 5 years have passed since last update.

[TravisCI] Node.jsプロジェクト以外でNode.jsを使う方法

Last updated at Posted at 2017-01-18

nvm をインストールする

Travisにはデフォルトで nvm@0.32.0 がインストールされている(2017-05-31)

.travis.yml
language: ruby # not "node_js"

cache:
  bundler: true
  directories:
    - node_modules

before_install:
  # if package.json exists
  - nvm install $(jq -r '.engines.node' package.json)

  # Or if .nvmrc exists
  - nvm install 
package.json
{
  "engines": {
    "node": "6"
  }
}
.nvmrc
6

See https://github.com/creationix/nvm#nvmrc.

最新の nvm を使いたい場合

.travis.yml
before_install:
  # Install nvm and Node.js (https://github.com/creationix/nvm#install-script)
  - export NVM_VERSION=v0.33.0
  - export NVM_DIR="$HOME/.nvm"
  - rm -rf "$NVM_DIR"
  - curl -o- https://raw.githubusercontent.com/creationix/nvm/${NVM_VERSION}/install.sh | bash
  - . "$NVM_DIR/nvm.sh" || true # if .nvmrc exists then returns 3 exit status
  - nvm install

See https://github.com/creationix/nvm#install-script.

Yarn を使う場合

.travis.yml
# https://docs.travis-ci.com/user/caching/
cache:
  bundler: true
  yarn: true

before_install:
  # After nvm installation

  # Install Yarn (https://yarnpkg.com/en/docs/install-ci#travis-tab)
  - curl -o- -L https://yarnpkg.com/install.sh | bash
  - export PATH="$HOME/.yarn/bin:$PATH"
  - yarn install

See https://yarnpkg.com/en/docs/install-ci#travis-tab.

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2