[英]`npm build` doesn't run the script named “build” in package.json
For a new module I'm trying to use npm build
without gulp / Grunt / other specialised build tools.对于一个新模块,我尝试使用
npm build
而没有 gulp / Grunt / 其他专门的构建工具。
"scripts": {
"build": "node build.js"
},
My build.js is simply我的 build.js 很简单
console.log('Hello')
However, running然而,运行
npm build
Simply exits without printing anything, with a status of 0.直接退出而不打印任何内容,状态为 0。
Running:跑步:
npm install
Also does all the normal things, but does not run build.js either.也做所有正常的事情,但也不运行 build.js。
How can I make npm run my build script?如何让 npm 运行我的构建脚本?
Edit: even simple bash commands don't seem to work, eg编辑:即使是简单的 bash 命令似乎也不起作用,例如
"scripts": {
"build": "touch TESTFILE"
},
Doesn't make a file with that name.不制作具有该名称的文件。
Unfortunately npm build
is already an internal command, as described in the docs :不幸的是
npm build
已经是一个内部命令,如文档中所述:
This is the plumbing command called by npm link and npm install.
这是由 npm link 和 npm install 调用的管道命令。 It should generally not be called directly.
一般不应直接调用。
Because that command already exists, it always shadows over your "build": "node build.js"
.因为该命令已经存在,所以它总是
"build": "node build.js"
在你的"build": "node build.js"
。
The fully-qualified way to run your own script is with run-script
or its alias run
:运行您自己的脚本的完全限定方式是使用
run-script
或其别名run
:
$ npm run build
npm start
and others are the short-hand way, but is only an option when an existing npm command doesn't shadow it, like npm build
does. npm start
和其他是速记方式,但只有在现有 npm 命令不隐藏它时才可以选择,就像npm build
那样。
For posterity (as others have mentioned) npm build
is used by npm to build native C/C++ Node addons using node-gyp .对于后代(正如其他人所提到的),
npm build
使用 npm build 来使用node-gyp构建本机 C/C++ Node 插件。
The script named as "build" in package.json
is not special in any way. package.json
名为“build”的脚本在任何方面都没有什么特别之处。 The only way to get it to run is to call:让它运行的唯一方法是调用:
npm run-script build
There are some names which are called automatically by npm , but "build" is not one of them.有一些名称由 npm 自动调用,但“build”不是其中之一。 The full list is:
完整列表是:
prepublish
, publish
, postpublish
prepublish
, publish
, publish
postpublish
preinstall
, install
, postinstall
preinstall
, install
, postinstall
preuninstall
, uninstall
, postuninstall
uninstall
preuninstall
, uninstall
, uninstall
postuninstall
preversion
, version
, postversion
preversion
version
, version
, 后postversion
pretest
, test
, posttest
pretest
, test
, posttest
prestop
, stop
, poststop
prestop
, stop
, poststop
prestart
, start
, poststart
prestart
, start
, poststart
prerestart
, restart
, postrestart
restart
prerestart
, restart
, postrestart
preCUSTOM
and postCUSTOM
for custom script names. preCUSTOM
和postCUSTOM
用于自定义脚本名称。好的,要自己运行构建,请使用:
npm run-script build
I had a problem with npm run build
not printing anything.我遇到了
npm run build
不打印任何内容的问题。 ended up using npm run build --verbose
to get the output I needed.最终使用
npm run build --verbose
来获得我需要的输出。
A folder containing a package.json file in its root
在其根目录中包含 package.json 文件的文件夹
Try using npm scripts in your package.json, like the classic npm start尝试在 package.json 中使用npm 脚本,就像经典的 npm start
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.