# Workspace and project file structure
# 工作区和项目文件结构
You develop applications in the context of an Angular [workspace](guide/glossary#workspace). A workspace contains the files for one or more [projects](guide/glossary#project). A project is the set of files that comprise a standalone application or a shareable library.
你会以 Angular [工作空间](guide/glossary#workspace)作为上下文来开发应用。工作空间包含一个或多个[项目](guide/glossary#project)的文件集。一个项目就是一组包含独立应用或可共享库的文件。
The Angular CLI `ng new` command creates a workspace.
Angular CLI 的 `ng new`命令可以创建一个工作空间。
ng new <my-project>
When you run this command, the CLI installs the necessary Angular npm packages and other dependencies in a new workspace, with a root-level application named *my-project*.
The workspace root folder contains various support and configuration files, and a README file with generated descriptive text that you can customize.
当你运行这个命令时,CLI 会在一个新的工作区中安装必需的 Angular npm 包和其它依赖项,其根应用名叫 *my-project*。
该工作空间的根文件夹中包含一些工作空间配置文件,和一个带有自动生成的描述性文本的自述文件,你可以自定义它。
By default, `ng new` creates an initial skeleton application at the root level of the workspace, along with its end-to-end tests.
The skeleton is for a simple Welcome application that is ready to run and easy to modify.
The root-level application has the same name as the workspace, and the source files reside in the `src/` subfolder of the workspace.
`ng new` 还会默认创建一个位于工作空间根级的骨架应用,及其端到端测试项目。这个骨架是一个简单的 Welcome 应用,它可以运行,也很容易修改。这个*根应用*与工作空间同名,其源文件位于工作空间的 `src/` 子文件夹中。
This default behavior is suitable for a typical "multi-repo" development style where each application resides in its own workspace.
Beginners and intermediate users are encouraged to use `ng new` to create a separate workspace for each application.
这种默认行为适用于典型的“多重(multi)仓库”开发风格,每个应用都位于它自己的工作空间中。建议初学者和中级用户使用 `ng new` 为每个应用创建一个单独的工作空间。
Angular also supports workspaces with [multiple projects](#multiple-projects).
This type of development environment is suitable for advanced users who are developing [shareable libraries](guide/glossary#library),
and for enterprises that use a "monorepo" development style, with a single repository and global configuration for all Angular projects.
Angular 还支持包含[多个项目](#multiple-projects)的工作空间。这种开发环境适用于正在开发[可共享库](guide/glossary#library)的高级用户,以及那些使用“单一(mono)仓库”开发风格的企业,它只需要一个仓库,而且所有 Angular 项目都使用全局配置。
To set up a monorepo workspace, you should skip the creating the root application.
See [Setting up for a multi-project workspace](#multiple-projects) below.
要设置单一仓库的工作空间,你应该跳过创建根应用的过程。请参阅下面的[设置多项目工作空间](#multiple-projects)部分。
## Workspace configuration files
## 工作区配置文件
All projects within a workspace share a [CLI configuration context](guide/workspace-config).
The top level of the workspace contains workspace-wide configuration files, configuration files for the root-level application, and subfolders for the root-level application source and test files.
每个工作空间中的所有项目共享同一个 [CLI 配置环境](guide/workspace-config) 。该工作空间的顶层包含着全工作空间级的配置文件、根应用的配置文件以及一些包含根应用的源文件和测试文件的子文件夹。
| WORKSPACE CONFIG FILES | PURPOSE |
| :--------------------- | :------------------------------------------|
| 工作空间配置文件 | 用途 |
| `.editorconfig` | Configuration for code editors. See [EditorConfig](https://editorconfig.org/). |
| `.editorconfig` | 代码编辑器的配置。参见 [EditorConfig](https://editorconfig.org/) 。 |
| `.gitignore` | Specifies intentionally untracked files that [Git](https://git-scm.com/) should ignore. |
| `.gitignore` | 指定 [Git](https://git-scm.com/) 应忽略的不必追踪的文件。 |
| `README.md` | Introductory documentation for the root app. |
| `README.md` | 根应用的简介文档. |
| `angular.json` | CLI configuration defaults for all projects in the workspace, including configuration options for build, serve, and test tools that the CLI uses, such as [TSLint](https://palantir.github.io/tslint/), [Karma](https://karma-runner.github.io/), and [Protractor](http://www.protractortest.org/). For details, see [Angular Workspace Configuration](guide/workspace-config). |
| `angular.json` | 为工作区中的所有项目指定 CLI 的默认配置,包括 CLI 要用到的构建、启动开发服务器和测试工具的配置项,比如 [TSLint](https://palantir.github.io/tslint/),[Karma](https://karma-runner.github.io/) 和 [Protractor](http://www.protractortest.org/)。欲知详情,请参阅 [Angular 工作空间配置](guide/workspace-config) 部分。 |
| `package.json` | Configures [npm package dependencies](guide/npm-packages) that are available to all projects in the workspace. See [npm documentation](https://docs.npmjs.com/files/package.json) for the specific format and contents of this file. |
| `package.json` | 配置工作空间中所有项目可用的 [npm包依赖](guide/npm-packages) 。有关此文件的具体格式和内容,请参阅 [npm 的文档](https://docs.npmjs.com/files/package.json) 。 |
| `package-lock.json` | Provides version information for all packages installed into `node_modules` by the npm client. See [npm documentation](https://docs.npmjs.com/files/package-lock.json) for details. If you use the yarn client, this file will be [yarn.lock](https://yarnpkg.com/lang/en/docs/yarn-lock/) instead. |
| `package-lock.json` | 提供 npm 客户端安装到 `node_modules` 的所有软件包的版本信息。欲知详情,请参阅 [npm 的文档](https://docs.npmjs.com/files/package-lock.json)。如果你使用的是 yarn 客户端,那么该文件[就是 yarn.lock](https://yarnpkg.com/lang/en/docs/yarn-lock/) 。 |
| `src/` | Source files for the root-level application project. |
| `src/` | 根项目的源文件。 |
| `node_modules/` | Provides [npm packages](guide/npm-packages) to the entire workspace. Workspace-wide `node_modules` dependencies are visible to all projects. |
| `README.md` | 根应用的介绍性文档。 |
| `tsconfig.json` | Default [TypeScript](https://www.typescriptlang.org/) configuration for projects in the workspace. |
| `tsconfig.json` | 工作空间中各个项目的默认 [TypeScript](https://www.typescriptlang.org/) 配置。 |
| `tslint.json` | Default [TSLint](https://palantir.github.io/tslint/) configuration for projects in the workspace. |
| `tslint.json` | 工作空间中各个项目的默认 [TSLint](https://palantir.github.io/tslint/) 配置。 |
## Application project files
## 应用项目文件
By default, the CLI command `ng new my-app` creates a workspace folder named "my-app" and generates a new application skeleton in a `src/` folder at the top level of the workspace.
A newly generated application contains source files for a root module, with a root component and template.
CLI 命令`ng new my-app` 会默认创建名为 “my-app” 的工作空间文件夹,并在 `src/` 文件夹下为工作空间顶层的根应用生成一个新的应用骨架。新生成的应用包含一个根模块的源文件,包括一个根组件及其模板。
When the workspace file structure is in place, you can use the `ng generate` command on the command line to add functionality and data to the application.
This initial root-level application is the *default app* for CLI commands (unless you change the default after creating [additional apps](#multiple-projects)).
当工作空间文件结构到位时,可以在命令行中使用 `ng generate` 命令往该应用中添加功能和数据。这个初始的根应用是 CLI 命令的*默认应用*(除非你在创建[其它应用](#multiple-projects)之后更改了默认值)。
Besides using the CLI on the command line, you can also use an interactive development environment like [Angular Console](https://angularconsole.com/), or manipulate files directly in the app's source folder and configuration files.
除了在命令行中使用 CLI 之外,你还可以使用像 [Angular Console](https://angularconsole.com/) 这样的交互式开发环境,或直接在应用的源文件夹和配置文件中操作这些文件。
For a single-application workspace, the `src/` subfolder of the workspace contains the source files (application logic, data, and assets) for the root application.
For a multi-project workspace, additional projects in the `projects/` folder contain a `project-name/src/` subfolder with the same structure.
对于单应用的工作区,工作空间的 `src/` 子文件夹包含根应用的源文件(应用逻辑、数据和静态资源)。对于多项目的工作空间,`projects/` 文件夹中的其它项目各自包含一个具有相同结构的 `project-name/src/` 子目录。
### Application source files
### 应用源文件
Files at the top level of `src/` support testing and running your application. Subfolders contain the application source and application-specific configuration.
顶级文件 `src/` 为测试并运行你的应用提供支持。其子文件夹中包含应用源代码和应用的专属配置。
| APP SUPPORT FILES | PURPOSE |
| :---------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 应用支持文件 | 目的 |
| `app/` | Contains the component files in which your application logic and data are defined. See details [below](#app-src). |
| `app/` | 包含定义应用逻辑和数据的组件文件。详见[下文](#app-src) 。 |
| `assets/` | Contains image and other asset files to be copied as-is when you build your application. |
| `assets/` | 包含要在构建应用时应该按原样复制的图像和其它静态资源文件。 |
| `environments/` | Contains build configuration options for particular target environments. By default there is an unnamed standard development environment and a production ("prod") environment. You can define additional target environment configurations. |
| `environments/` | 包含特定目标环境的构建配置选项。默认情况下,有一个无名的标准开发环境和一个生产(“prod”)环境。你还可以定义其它的目标环境配置。 |
| `favicon.ico` | An icon to use for this application in the bookmark bar. |
| `favicon.ico` | 用作该应用在标签栏中的图标。 |
| `index.html` | The main HTML page that is served when someone visits your site. The CLI automatically adds all JavaScript and CSS files when building your app, so you typically don't need to add any `