这个问题与让 Angular 应用程序监视库更改并进行自我更新 https://stackoverflow.com/questions/60473727/make-angular-app-watch-for-libraries-changes-and-update-itself。但是,这个问题从未成功回答,因为它适用于多个库的使用。我还回顾了Angular 库和实时重新加载 https://stackoverflow.com/questions/59356732/angular-library-and-live-reload/59706221#59706221并调查了这两个问题的答案和链接。
我的应用程序使用两个库:lib-1
and lib-2
。编辑这些文件时,它们将被忽略,并且应用程序不会重新编译。要查看更改,我必须重新启动服务器,这确实会减慢速度。
我的期望是,在编辑库文件时应该重新编译应用程序,就像编辑其他应用程序内部文件时一样。
这是我继承的一个Angular项目,原作者已经不在了。我正在使用 Angular v10 和 npm 6.14.11
最初的 npm 脚本是:
"start:staging": "ng serve --configuration-staging --host 0.0.0.0 --port 8080 --disableHostCheck",
"build:lib-1": "ng build lib-1 && cpx projects/lib-1/src/lib/theme.scss dist/lib-1",
"build:lib-2": "ng build lib-2 && cpx projects/lib-2/src/lib/theme.scss dist/lib-2",
"build:libs": "npm run build:lib-1 && npm run build:lib-2",
有了这些,我首先跑npm run build:libs
, then npm run start:staging
。如前所述,这不会“监视”我的库的更改。
我审查了这些建议和其他 SO 问题(上面),并确保npm-run-all
, wait-on
and rimraf
库现已安装。
我编写了这些新的 npm 脚本:
"clean": "rimraf dist",
"start-app": "wait-on dist/lib-1/fesm2015 dist/lib-2/fesm2015 && start:staging --poll 2000",
"watch:lib-1": "npm run build:lib-1 --watch",
"watch:lib-2": "npm run build:lib-2 --watch",
"watch-libs": "npm-run-all --parallel watch:lib-1 watch:lib-2",
"watch-all": "npm-run-all clean --parallel watch-libs start-app"
而且,我正在使用预先存在的start:staging
脚本,如所写。
I run npm run watch-all
.
该脚本运行并继续并行构建库(坏主意?),然后抛出错误:sh: start:staging: command not found
.
我删除了--parallel
切换并再次尝试,得到同样的错误。
The start:staging
script 确实在脚本对象中,我不明白为什么没有找到它。
我希望得到一些有关纠正语法的明智建议,以便应用程序能够编译并监视我的库文件以及应用程序内部的其他文件src
folder.