文法:ng build project options
作用:編譯
Angular應用到 output 檔案夾裡,通常名稱為 dist. 必須在工作空間目錄下執行。

輸入參數:project, 可以為應用或者 library.
支援的參數
使用 ng build --help 檢視所有支援的參數。
其中這個選項值得一說:–prod
Shorthand for “–configuration=production”.
是 --configuration=production 的簡寫形式。
When true, sets the build configuration to the production target.
将 build configuration 設定成 production target.
By default, the production target is set up in the workspace configuration such that all builds make use of bundling, limited tree-shaking, and also limited dead code elimination.
預設情況下,production target 在工作空間配置中設定,參考官網。
Workspace configuration 對應的檔案是 angular.json.
A file named angular.json at the root level of an Angular workspace provides workspace-wide and project-specific configuration defaults for build and development tools provided by the Angular CLI.
下圖是 SAP Spartacus workspace configuration 内容:
version: The configuration-file version.
newProjectRoot: Path where new projects are created. Absolute or relative to the workspace folder.
新項目建立,一律放在 feature-libs 檔案夾下面。
options:This section contains default build target options, used when no named alternative configuration is specified.
包含預設的 build target 選項。
Alternate build configurations
Angular CLI comes with two build configurations: production and development.
By default, the ng build command uses the production configuration
預設情況下,ng build 使用 production 配置。
Production 配置意味着下列優化:
Bundling files - 将檔案打包合并在一起
Minimizing excess whitespace - 删除所有空白字元
Removing comments and dead code - 删除注釋和永遠不會執行的代碼
Rewriting code to use short, mangled names (minification) - 精簡變量名
You can define and name additional alternate configurations (such as stage, for instance) appropriate to your development process. Some examples of different build configurations are stable, archive and next used by AIO itself, and the individual locale-specific configurations required for building localized versions of an app.
可以自定義配置,比如 stage,archive 等等。
可以一次性傳入多個配置:ng build --configuration stage,fr
In this case, the command parses the named configurations from left to right. If multiple configurations change the same setting, the last-set value is the final one.
如果多個配置都修改了同一個設定,以最後一個配置為準。
Assets configuration
build 的過程中直接拷貝的資源。
Each build target configuration can include an assets array that lists files or folders you want to copy as-is when building your project. By default, the src/assets/ folder and src/favicon.ico are copied over.