首页 > 解决方案 > 如何在每个 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');
})();

标签: javascriptangulartypescriptnpm-scriptsconcurrently

解决方案


这是不可能的。 ng serve在监视模式下运行时不会完成,因此在它之后运行的链接项目将无效。该serve命令对此没有任何挂钩。


推荐阅读