javascript - `npm build` 没有在 package.json 中构建 't r

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

"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 已经是 internal 命令,如 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 用于使用 node-gyp 构建原生 C/C++ Node 插件.

关于javascript - `npm build` 没有在 package.json 中构建 't run the script named ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29939697/

相关文章:

xcode - 无法附加到进程 ID Xcode

Xcode - 但是......我们的文件在哪里?

java - 构建与编译 (Java)

java - leiningen - 如何为本地 jar 添加依赖项?

build - 编译代码和可执行代码有什么区别?

build - gmake 和 make 有什么区别?

configuration - 在 Xcode 中添加构建配置

xml - 防止将引用的程序集 PDB 和 XML 文件复制到输出

android - 错误 :Execution failed for task ':app:comp

java - 如何在 Maven 中读取外部属性文件