`npm build` 没有 运行 package.json 中名为 "build" 的脚本

`npm build` doesn't run the script named "build" in package.json

对于一个新模块,我尝试在没有 gulp / G运行t / 其他专门构建工具的情况下使用 npm build

"scripts": {
  "build": "node build.js"
},

我的build.js简直就是

console.log('Hello')

不过,运行宁

npm build

不打印任何东西直接退出,状态为0。

运行:

npm install

也可以做所有正常的事情,但 运行 build.js 也不会。

如何让 npm 运行 成为我的构建脚本?

编辑:即使是简单的 bash 命令似乎也不起作用,例如

"scripts": {
    "build": "touch TESTFILE"
},

不使用该名称创建文件。

Npm build 预计

A folder containing a package.json file in its root

尝试在 package.json 中使用 npm scripts,就像经典的 npm start

好的,要 运行 自己构建,请使用:

npm run-script build

不幸的是 npm build 已经是一个 内部 命令,如 in the docs:

所述

This is the plumbing command called by npm link and npm install. It should generally not be called directly.

因为该命令已经存在,所以它总是遮蔽您的 "build": "node build.js"

运行您自己的脚本的完全合格方法是 run-script or its alias run:

$ npm run build

npm start 和其他是简写方式,但只有在现有 npm 命令不隐藏它时才可以选择,例如 npm build


对于子孙后代(正如其他人提到的)npm build 被 npm 使用 C/C++ 使用 node-gyp.

构建原生 C/C++ 节点插件

我有一个问题 npm run build 没有打印任何东西。最终使用 npm run build --verbose 获得我需要的输出。

package.json中名为"build"的脚本没有任何特殊之处。让它达到 运行 的唯一方法是调用:

npm run-script build

There are some names which are called automatically by npm,但 "build" 不是其中之一。完整列表是:

  • prepublishpublishpostpublish
  • preinstallinstallpostinstall
  • preuninstalluninstallpostuninstall
  • preversionversionpostversion
  • pretesttestposttest
  • prestopstoppoststop
  • prestartstartpoststart
  • prerestartrestartpostrestart
  • preCUSTOMpostCUSTOM 用于自定义脚本名称。