javascript - 如何在每个 ng serve 构建后链接 npm 脚本调用?
问题描述
我试图ng serve
在运行时链接脚本调用,但是当我运行此命令时,第二个链接脚本build-components.js
仅在第一次调用时运行。
我认为在这里同时打包将允许两个脚本根据文档https://www.npmjs.com/package/concurrently按顺序运行
我的目标是build-components.js
每次运行时运行脚本ng serve
(即检测源更改)。
Package.json 脚本:
"build:watch": "concurrently \"ng serve --port 4003\" \"node build-components.js\""
测试
concurrently "ng serve --port 4003" "node build-components.js"
[1] node build-components.js exited with code 0
[0] i 「wds」: Project is running at http://localhost:4003/webpack-dev-server/
问题:
每次 ng serve 构建后如何运行另一个 npm 脚本?
我还查看了 npm post 挂钩,但这似乎也没有在运行脚本后ng serve
运行。
http://www.marcusoft.net/2015/08/pre-and-post-hooks-for-npm-scripting.html#hooks-pre-and-post
这是build-components.js
供参考的脚本。它将一些额外的构建文件复制到公共文件夹以进行托管:
const fs = require('fs-extra');
const concat = require('concat');
(async function build() {
const js = [
'./dist/app/runtime-es2015.js',
'./dist/app/main-es2015.js',
'./dist/app/scripts.js',
];
const css = ['./dist/app/styles.css'];
await fs.ensureDir('components');
await concat(js, 'components/component.js');
await concat(css, 'components/component.css');
})();
解决方案
这是不可能的。 ng serve
在监视模式下运行时不会完成,因此在它之后运行的链接项目将无效。该serve
命令对此没有任何挂钩。
推荐阅读
- python - numpy 中的 set_printoptions() 错误
- database - MongoNetworkError:连接 ETIMEDOUT
- python - 如何通过python脚本检查cpu消耗
- typescript - 将 TypeScript 声明从本地私有模块导入应用程序
- android - 具有相同高度的子视图,具有最大高度的视图
- vba - Outlook宏即使在删除时也会执行
- algorithm - 递归:T(n/4) + T(n/2) + n^2 使用树方法
- java - Jsoup.body() 返回空正文
- javascript - 如何使用 forEach-Loop 将数组的内容转为另一个数组?
- powershell - 导出然后导入自定义的 WMI 命名空间