简体   繁体   English

覆盖NPM项目的`npm install`脚本

[英]Override `npm install` script for NPM project

I have an NPM project, when npm install is run, I'd like to run a custom script. 我有一个NPM项目,当npm install时,我想运行一个自定义脚本。

I tried using this in package.json: 我尝试在package.json中使用它:

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "install": "./scripts/install.sh",   // <<<<
 },

but that actually just resulted in an infinite loop. 但这实际上只是导致无限循环。 The reason I am looking for this, is because there are tools that simply call npm install , so I can't control what they run. 我正在寻找这个的原因是因为有些工具只是简单地调用npm install ,所以我无法控制它们运行的​​内容。 Otherwise, if I had control, I would just call ./scripts/install.sh myself instead. 否则,如果我有控制权,我会自己调用./scripts/install.sh

Note that this is probably not the best idea, just curious if it's possible. 请注意,这可能不是最好的主意,只是好奇,如果可能的话。

Note my install script looks something like this: 请注意我的安装脚本如下所示:

#!/usr/bin/env bash

export FOO="bar";
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true";

npm install

Use preinstall to run code before npm install . 使用preinstallnpm install之前运行代码。 Don't try to override npm install in this fashion where you would end up with an infinite loop of calls to npm install . 不要试图以这种方式覆盖npm install ,你最终会对npm install进行无限循环调用。

You can also set environment variables using the config property of package.json . 您还可以使用package.jsonconfig属性设置环境变量。 See docs for details 有关详细信息,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM