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

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

问题描述

有关一个新的模块,我尝试使用 NPM构建 无一饮而尽/步兵/其他专门构建工具。

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.

我怎样才能让故宫运行我的构建脚本?

编辑:即使是简单的bash命令似乎不工作,如:

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

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

不与该名称的文件。

Doesn't make a file with that name.

推荐答案

的问题是, NPM构建实际上已经是一个的内部的命令,如在文档中描述的 的:

The issue is that npm build is actually already an internal command, as described in the docs:

这是故宫链路和NPM安装一个名为管道命令。
  它一般不应直接调用。

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

由于该命令已经存在,它总是阴影在你的建:节点build.js

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

运行自己的脚本的完全限定方法是使用 运行脚本或它的别名运行

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

$ npm run build

NPM启动等是短手为完全合格的运行脚本,但仅仅是一个选项​​时,现有的NPM命令没有它的影子,像 NPM构建一样。基本上,如果一个内置NPM命令没有发现它会尝试找到并使用任何匹配的那个从你的脚本的package.json属性。

npm start and others are short-hand for the fully-qualified run-script, but is only an option when an existing npm command doesn't shadow it, like npm build does. Basically, if an built-in npm command isn't found it will try to find and use any matching one from your "scripts" package.json property.

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

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