`npm build` 不运行名为“build"的脚本;在 package.json 中 [英] `npm build` doesn't run the script named "build" in package.json

查看:33
本文介绍了`npm build` 不运行名为“build"的脚本;在 package.json 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个新模块,我正在尝试使用 npm build 而没有 gulp/Grunt/其他专门的构建工具.

For a new module I'm trying to use npm build without gulp / Grunt / other specialised build tools.

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

我的 build.js 很简单

My build.js is simply

console.log('Hello')

但是,运行

npm build

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

Simply exits without printing anything, with a status of 0.

运行:

npm install

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

Also does all the normal things, but does not run build.js either.

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

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

even simple bash commands don't seem to work, eg

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

不创建具有该名称的文件.

Doesn't make a file with that name.

推荐答案

不幸的是,npm build 已经是一个内部命令,如在文档中:

Unfortunately npm build is already an internal command, as described in the docs:

这是由 npm link 和 npm install 调用的管道命令.一般不应直接调用.

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

因为该命令已经存在,它总是会覆盖您的build":node build.js".

Because that command already exists, it always shadows over your "build": "node build.js".

运行您自己的脚本的完全限定方式是使用 run-script 或其别名 run:

The fully-qualified way to run your own script is with run-script or its alias run:

$ npm run build

npm start 和其他是速记方式,但仅在现有 npm 命令不隐藏它时才作为一种选择,就像 npm 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 build 被 npm 用于使用 node-gyp.

For posterity (as others have mentioned) npm build is used by npm to build native C/C++ Node addons using node-gyp.

这篇关于`npm build` 不运行名为“build"的脚本;在 package.json 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆