ng new
建立一個新工作空間和一個初始 Angular 應用。
Creates a new workspace and an initial Angular application.
ng new <name> [options]
ng n <name> [options]
說明
建立並初始化一個新的 Angular 應用程式,該應用程式是新工作區的預設專案。
Creates and initializes a new Angular application that is the default project for a new workspace.
提供互動式提示以提供可選配置,例如新增路由支援。可以放心地為所有提示選擇其預設值。
Provides interactive prompts for optional configuration, such as adding routing support. All prompts can safely be allowed to default.
新的工作空間資料夾名稱就是指定的專案名稱,並且在最上層包含了配置檔案。
The new workspace folder is given the specified project name, and contains configuration files at the top level.
預設情況下,新的初始應用程式(與工作空間名稱相同)的檔案放置在
src/
子資料夾中。相應的端到端測試位於e2e/
子資料夾中。By default, the files for a new initial application (with the same name as the workspace) are placed in the
src/
subfolder. Corresponding end-to-end tests are placed in thee2e/
subfolder.新應用程式的配置位於工作區配置檔案
angular.json
中projects
部分的專案名稱下。The new application's configuration appears in the
projects
section of theangular.json
workspace configuration file, under its project name.你在工作空間中產生的後續應用程式位於
projects/
子資料夾中。Subsequent applications that you generate in the workspace reside in the
projects/
subfolder.
如果你計劃在工作空間中放多個應用程式,則可以透過將 --createApplication
選項設定為 false 來建立一個空的工作空間。然後,你可以使用 ng generate application
建立一個初始應用程式。這能讓工作空間的名稱不同於初始應用程式的名稱,並確保所有應用程式都位於 /projects
子資料夾中,並與配置檔案的結構匹配。
If you plan to have multiple applications in the workspace, you can create an empty workspace by setting the --createApplication
option to false. You can then use ng generate application
to create an initial application. This allows a workspace name different from the initial app name, and ensures that all applications reside in the /projects
subfolder, matching the structure of the configuration file.
引數
引數 | 說明 |
---|---|
<name> | 新工作空間和初始專案的名稱。 The name of the new workspace and initial project. |
選項
選項 | 說明 |
---|---|
--collection=collection | 用來產生初始應用的一組原理圖。 A collection of schematics to use in generating the initial application. 別名: -c |
--commit=true|false | 初始 git 儲存庫提交資訊。 Initial git repository commit information. 預設值: |
--create-application=true|false | 在新工作區的 “src” 資料夾中建立一個新的初始應用程式專案。如果為 false,則會建立一個沒有初始應用程式的空工作空間。然後,你可以使用 generate application 命令,以便讓所有應用程式都建立在自己的專案資料夾中。 Create a new initial application project in the 'src' folder of the new workspace. When false, creates an empty workspace with no initial application. You can then use the generate application command so that all applications are created in the projects folder. 預設值: |
--defaults=true|false | 對有預設值的選項禁用互動式輸入提示。 Disable interactive input prompts for options with a default. |
--directory=directory | 要在其中建立工作空間的目錄名稱。 The directory name to create the workspace in. |
--dry-run=true|false | 執行一遍並彙報其活動軌跡,但不真的寫入任何結果。 Run through and reports activity without writing out results. 預設值: 別名: -d |
--force=true|false | 強制覆蓋現存檔案。 Force overwriting of existing files. 預設值: 別名: -f |
--help= | 在控制檯顯示關於本命令的幫助資訊。 Shows a help message for this command in the console. 預設值: |
--inline-style=true|false | 在元件 TS 檔案中包含內聯樣式。預設情況下,將建立一個外部樣式檔案,並在元件 TypeScript 檔案中對其進行參考。 Include styles inline in the component TS file. By default, an external styles file is created and referenced in the component TypeScript file. 別名: -s |
--inline-template=true|false | 在元件 TS 檔案中包含內聯範本。預設情況下,將建立一個外部範本檔案,並在元件 TypeScript 檔案中對其進行參考。 Include template inline in the component TS file. By default, an external template file is created and referenced in the component TypeScript file. 別名: -t |
--interactive=true|false | 啟用互動式輸入提示。 Enable interactive input prompts. |
--legacy-browsers=true|false | 使用差異化載入新增對 Internet Explorer 等舊版瀏覽器的支援。 Add support for legacy browsers like Internet Explorer using differential loading. 預設值: |
--minimal=true|false | 建立沒有任何測試框架的工作空間。(僅用於學習目的。) Create a workspace without any testing frameworks. (Use for learning purposes only.) 預設值: |
--new-project-root= | 要建立的新專案的路徑。是相對於新工作空間根目錄的。 The path where new projects will be created, relative to the new workspace root. 預設值: |
--package-manager= | 用於安裝依賴項的套件管理器。 The package manager used to install dependencies. |
--prefix=prefix | 適用於初始專案的產生選擇器的字首。 The prefix to apply to generated selectors for the initial project. 預設值: 別名: -p |
--routing=true|false | 為初始專案產生一個路由模組。 Generate a routing module for the initial project. |
--skip-git=true|false | 不要初始化 git 儲存庫。 Do not initialize a git repository. 預設值: 別名: -g |
--skip-install=true|false | 不要安裝相依套件。 Do not install dependency packages. 預設值: |
--skip-tests=true|false | 不要為新專案產生 “spec.ts” 測試檔案。 Do not generate "spec.ts" test files for the new project. 預設值: 別名: -S |
--strict=true|false | 建立帶有更嚴格型別檢查和更嚴格捆綁套件預算設定的工作空間。此設定有助於提升可維護性,並預先捕獲 BUG。欲知詳情,參見 https://angular.cn/guide/strict-mode Creates a workspace with stricter type checking and stricter bundle budgets settings. This setting helps improve maintainability and catch bugs ahead of time. For more information, see https://angular.io/guide/strict-mode 預設值: |
--style= | 用於樣式檔案的副檔名/前處理器。 The file extension or preprocessor to use for style files. |
--verbose=true|false | 在輸出日誌中新增更多詳情。 Add more details to output logging. 預設值: 別名: -v |
--view-encapsulation= | 用在初始專案中的檢視封裝策略。 The view encapsulation strategy to use in the initial project. |