問題描述
將 nx 與 angular.json 一起使用時使用哪個構建器 (Which builder to use when using nx with angular.json)
我遷移了一個現有的 Angular 項目以使用 nx。但我不太確定我是否以正確的方式做到了,因為性能很差。
我現在從
"builder": "@angular‑devkit/build‑angular:browser",
切換到
"builder": "@nrwl/web:build",
和似乎性能變得更好了。但是還有更多,例如:
"builder": "@nrwl/angular:webpack‑browser",
"builder": "@nrwl/angular:ng‑packagr‑lite",
使用web:build是否正確?有什麼區別?不幸的是,我在他們的網站上找不到很好的解釋。任何人都可以指出我正確的方向嗎?什麼時候使用哪個構建器?有什麼區別?
參考解法
方法 1:
I had the same problem after an Nx update, so did a little search on their official website. It's sad that they don't provide sufficient documentation for migrations. However, as they have documented clearly in their @nrwl/angular:webpack‑browser page,
The webpack‑browser executor is very similar to the standard browser builder provided by the Angular Devkit. It allows you to build your Angular application to a build artifact that can be hosted online. There are some key differences:
- Supports Custom Webpack Configurations
- Supports Incremental Building
A customWebpackConfig
can be provided but is optional and still the Angular Devkit Configuration
takes priority.
Nx configuration has now been updated to version: 2
and "builder": "@angular‑devkit/build‑angular:browser",
was the standard way of specifying the executor in version: 1
. Check your Nx configuration version and if you want to update it to 2
, follow the instructions here.
方法 2:
I know it's been a couple of months, but for the sake of completeness: the ngPackagr one should be used for libraries only, as specified in their repo. Is that what you were trying to do? Also, what did you mean by poor performance?
If it's any reference (or for future visitors) I just created an NX app and it came with @angular‑devkit/build‑angular:browser
by default.
(by timtos、Chamath Kirinde、Alejandro L.)