NPM:如何在安装后运行?

noe*_*ace 54 node.js npm package.json

只是一个简单的问题:在我的node.js项目中,我怎么能只运行postinstall脚本,而不运行之前的安装?

仅供参考,这是我的package.json:

{
  "name": "gestionclientjs",
  ...,
  "dependencies": {
    ...
  },
  "repository": {},
  "devDependencies": {
    ...
  },
  "engines": {
    "node": ">=0.10.0"
  },
  "scripts": {
    "test": "grunt test",
    "postinstall" : "bower install && node ./app/server/dbSeed.js",
    "start": "node app/server/app.js"
  }
}
Run Code Online (Sandbox Code Playgroud)

现在,我跑:

npm install
Run Code Online (Sandbox Code Playgroud)

在我的项目中,但我想跑

npm postinstall
Run Code Online (Sandbox Code Playgroud)

当我想要的时候(当我确定依赖是好的时候).

rob*_*lep 67

您可以使用npm run SCRIPTNAME以下命令运行单个脚本条

$ npm run postinstall
Run Code Online (Sandbox Code Playgroud)

  • *facepalm*ok,thx ...我认为postinstall是一项特殊的操作...... (4认同)
  • @nonox 它的特别之处在于它会在 `npm install` 之后自动运行,但它也“只是”另一个脚本 :-) (3认同)
  • 是的,当然......我不知道为什么我没有想到它 (2认同)