JavaScriptNode.js

Publish my Node.js project to npm by Travis CI

Referenced: https://www.npmjs.com/package/travis-deploy-exampleReferenced: https://docs.travis-ci.com/user/dep […]

広告ここから
広告ここまで

Referenced: https://www.npmjs.com/package/travis-deploy-example
Referenced: https://docs.travis-ci.com/user/deployment/npm/

Step by Step

1: Create npm token

We have to get npm token to publish your packages from Travis CI. You can get the token byhttps://www.npmjs.com/settings/{YOUR_USERNAME}/tokens to put theCreate New Tokenbutton.

2: Set an environment variable in the Travis CI

You can put the token as an environment variable in the Travis CI. Let’s put the token into it name likeNPM_TOKEN.

Note: You can encrypt the token by Travis command.

3: Define publish conf into the .travis.yml

You can define the publishing configuration like this.

language: node_js
node_js:
  - '8'
install:
  - npm install
script:
  - npm run lint
  - npm test
deploy:
  provider: npm
  email: 'hoge@example.com'
  api_key: $NPM_TOKEN
  on:
    tags: true

In this case, you can publish your packages only push tagged artifact like git tag vx.x.x. If you want to publish productionbranch, you can define like this.

deploy:
  ...
  on:
    branch: production

4: Publish

Finally, you can publish your package by only Git command.

$ git add ./
$ git commit -m "new feature"
$ git tag v1.0.0
$ git push origin master v1.0.0

After running these command, we need to just wait for the email from npm that publishing complete.

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts