最終更新:2023-08-25 (金) 10:24:40 (327d)  

package.json/scripts
Top / package.json / scripts

https://docs.npmjs.com/cli/v7/using-npm/scripts

  • npm run <コマンド>/npm run-script <コマンド>で実行、それ以外に下記のプリセットがある
  "scripts": {
    "start": "node index.js"
  },

ライフサイクル操作の順序

npm cache add?

  • prepare

npm ci

  • preinstall
  • install
  • postinstall
  • prepublish
  • preprepare
  • prepare
  • postprepare

npm diff?

  • prepare

npm install

  • These also run when you run npm install -g <pkg-name>
  • preinstall
  • install
  • postinstall
  • prepublish
  • preprepare
  • prepare
  • postprepare

npm pack?

  • prepack
  • prepare
  • postpack

npm publish?

  • prepublishOnly
  • prepack
  • prepare
  • postpack
  • publish
  • postpublish

npm rebuild?

  • preinstall
  • install
  • postinstall
  • prepare

npm restart?

  • prerestart
  • restart
  • postrestart

npm run <user defined>

  • pre<user-defined>
  • <user-defined>
  • post<user-defined>

npm start

  • prestart
  • start
  • poststart
  • If there is a server.js file in the root of your package, then npm will default the start command to node server.js.
    • prestart and poststart will still run in this case.

npm stop

  • prestop
  • stop
  • poststop

npm test

  • pretest
  • test

関連