是否存在任何npm选项来禁用postinstall脚本,同时安装包?或者从package.json重写任何字段?
不可能只禁用postinstall脚本。然而,你可以禁用所有脚本使用:
$ npm install --ignore-scripts
正如delbertooo在评论中提到的,这也会禁用依赖项的脚本。
对于你自己的库,我推荐一些简单的方法:
#!/usr/bin/env bash
## this is your postinstall.sh script:
set -e;
if [ "$your_pkg_skip_postinstall" == "yes" ]; then
echo "skipping your package's postinstall routine.";
exit 0;
fi
然后用以下方法安装NPM:
your_pkg_skip_postinstall="yes" npm install
我想禁用postinstall脚本为我的项目,但希望我的项目的依赖的所有脚本运行时,我做npm安装。 这就是我最后做的事。
创建一个脚本。/scripts/skip.js
if (process.env.SKIP_BUILD) {
process.exit(0);
} else {
process.exit(1);
}
在你的包裹里。json文件
"scripts": {
...
"postinstall": "node ./scripts/skip.js || npm run build",
...
}
现在只需设置环境变量SKIP_BUILD=1,以防止构建包,您的依赖项将正常构建
SKIP_BUILD=1 npm install
如果你正在使用NPM >= 8,你也可以暂时删除postinstall脚本:
npm pkg set scripts.postinstall="echo no-postinstall"
npm install
或者在NPM 7中,像这样:
npm set-script postinstall ""
npm install
来源: https://docs.npmjs.com/cli/v7/commands/npm-set-script/
推荐文章
- 禁用包的postinstall脚本
- Node.js上的html解析器
- 错误:无法找到模块“webpack”
- 在node.js中使用async / await文件系统
- NodeJS -用NPM安装错误
- 如何为本地安装npm包设置自定义位置?
- 回调函数来处理管道的完成
- Express函数中的“res”和“req”参数是什么?
- node.js TypeError:路径必须是绝对路径或指定根路径到res.sendFile[解析JSON失败]
- Passport.js -错误:序列化用户到会话失败
- Node.js vs .Net性能
- 从电子应用程序中删除菜单栏
- 如何用node.js实现一个安全的REST API
- 如何处理Node.js中的循环依赖
- 在猫鼬,我如何排序的日期?(node . js)