node.js - Run another yarn/npm task within a package.json, without specifying yarn or npm
问题描述
I have a task in my package.json "deploy", which needs to first call "build". I have specified it like this:
"deploy": "yarn run build; ./deploy.sh",
The problem is that this hard codes yarn
as the package manager. So if someone doesn't use yarn
, it doesn't work. Switching to npm
causes a similar issue.
What's a good way to achieve this while remaining agnostic to the choice of npm
or yarn
?
解决方案
一种简单的方法是使用npm-run-all包,其文档指出:
纱线兼容性如果使用 Yarn 调用脚本,npm-run-all 将正确使用 Yarn 执行计划的子脚本。
所以你可以这样做:
"predeploy": "run-s build",
"deploy": "./deploy.sh",
predeploy
根据您调用deploy
任务的方式,该步骤将使用 npm 或 yarn。
我认为最好让 package.json 中的运行保持包管理器不可知,这样它们就不会绑定到特定的包管理器,但是在项目中,同意使用单个包管理器可能是谨慎的,所以你没有处理冲突的锁文件。
推荐阅读
- r - 在函数内调用时数据库连接 UI 不显示
- android - 如何在 Android 11.0 上使用 webview 加载本地图片?
- powerdesigner - 在存储库 PowerDesigner 中自定义版本
- android - 使用父片段作为所有者在 ViewPager 中共享 ViewModel
- pydev - Eclipse 4.8 推荐安装哪个 PyDev 版本
- typescript - 如何突出显示文本区域中的文本并在控制台中打印突出显示的文本?
- c# - 对于这种特殊情况,如何检查变量是否非双精度?
- database - 在 FastaApi 中请求文件
- reactjs - “水合作用”如何与 React 服务器组件一起工作?
- c++ - C++ 单 * 和 **