> For the complete documentation index, see [llms.txt](https://brianwu.gitbook.io/brian/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brianwu.gitbook.io/brian/angular/bu-shu.md).

# 部署

參考資料:(<https://angular.tw/guide/deployment>)

在開發過程中，你通常會使用 `ng serve` 命令來藉助 [webpack-dev-server](https://webpack.js.org/guides/development/#webpack-dev-server) 在本地記憶體中建構、監控和提供服務。但是，當你打算部署它時，就必須使用 `ng build` 命令來建構應用並在其它地方部署這些建構成果。

&#x20;預設情況下，輸出目錄是 `dist/project-name/`。要輸出到其它資料夾，就要修改 `angular.json` 中的 `outputPath`。

### 生產環境的優化

```
ng build --prod
```

* [預先(AOT)編譯](https://angular.tw/guide/aot-compiler)：預編譯 Angular 的元件範本。
* [生產模式](https://angular.tw/guide/deployment#enable-prod-mode)：部署到啟用了*生產模式*的生產環境。
* 打包：把你的多個應用於函式庫檔案拼接到少量包（bundle）中。
* 最小化：刪除多餘的空格、註釋和可選令牌。
* 混淆/醜化：重寫程式碼，使用簡短的、不容易理解的變數名和函式名。
* 消除死程式碼：刪除未參考過的模組和很多未用到的程式碼。
