7
3

More than 5 years have passed since last update.

npm ライブラリを作る時、 publish 用の run script を組んでおくと便利

Posted at

npm は npm version patch と打つと package.json の version を更新して tag も打ってくれる。
しかし publish するには git push して npm publish して〜とやらないといけないので面倒。

こんな感じで run script 組んでおくと publish がコマンド1発でいけて便利。

{
  "scripts": {
    "test": "jest",
    "build": "tslint -p tslint.json && tsc -d",
    "publish:patch": "yarn run build && npm version patch && git push origin master && git push origin --tags && npm publish --access=public",
    "publish:minor": "yarn run build && npm version minor && git push origin master && git push origin --tags && npm publish --access=public",
    "publish:major": "yarn run build && npm version major && git push origin master && git push origin --tags && npm publish --access=public"
  }
}

こんな感じで実行できる。

npm run publish:patch
npm run publish:minor
npm run publish:major

ちなみに、 yarn run publish:patch はだめ。 yarn では npm publish コマンドが使えないっぽい。

7
3
0

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
7
3