# Workspace and project file structure # 工作区与项目文件的结构 You develop apps 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 app, a library, or a set of end-to-end (e2e) tests. 你要在 Angular [工作区](guide/glossary#workspace)的上下文环境中开发应用。每个工作区中包括一个或多个[项目](guide/glossary#project)的文件。每个项目是一组文件,由标准应用、库或一组端到端(e2e)测试组成。 The Angular CLI command `ng new ` gets you started. When you run this command, the CLI installs the necessary Angular npm packages and other dependencies in a new workspace, with a root folder named *project_name*. It also creates the following workspace and starter project files: Angular CLI 命令 `ng new ` 可以帮你开始项目。 当你运行该命令时,CLI 会在新建的工作区(以 *project_name* 为根目录)中,安装必要的 Angular npm 包和其它依赖。 它还会创建如下的工作区和最初的项目文件: * An initial skeleton app project, also called *project_name* (in the `src/` subfolder). 一个初始的骨架应用项目,也叫 *project_name*(位于 `src/` 子目录下)。 * An end-to-end test project (in the `e2e/` subfolder). 一个端到端测试项目(位于 `e2e/` 子目录下)。 * Related configuration files. 相关配置文件。 The initial app project contains a simple Welcome app, ready to run. 初始的应用项目包含一个简单的 Welcome 应用,随时可以运行。 ## Workspace files ## 工作区文件 The top level of the workspace contains a number of workspace-wide configuration files. 工作区的顶级包含一系列工作区级的配置文件。 | 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/) 要忽略的非跟踪的文件。 | | `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)。 | | `node_modules` | Provides [npm packages](guide/npm-packages) to the entire workspace. | | `node_modules` | 提供给整个工作区的 [npm 包](guide/npm-packages)。 | | `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 文档](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 documentation](https://docs.npmjs.com/files/package-lock.json)。如果你使用 yarn 客户端,此文件会由 [yarn.lock](https://yarnpkg.com/lang/en/docs/yarn-lock/) 代替。 | | `tsconfig.json` | Default [TypeScript](https://www.typescriptlang.org/) configuration for apps in the workspace, including TypeScript and Angular template compiler options. See [TypeScript Configuration](guide/typescript-configuration). | | `tsconfig.json` | 工作区中所有应用的默认 [TypeScript](https://www.typescriptlang.org/) 配置。包括 TypeScript 选项和 Angular 模板编译器选项。参见 [TypeScript 配置](guide/typescript-configuration)。 | | `tslint.json` | Default [TSLint](https://palantir.github.io/tslint/) configuration for apps in the workspace. | | `tslint.json` | 工作区中所有应用的默认 [TSLint](https://palantir.github.io/tslint/) 配置。 | | `README.md` | Introductory documentation. | | `README.md` | 介绍文档 | All projects within a workspace share a [CLI configuration context](guide/workspace-config). Project-specific [TypeScript](https://www.typescriptlang.org/) configuration files inherit from the workspace-wide `tsconfig.*.json`, and app-specific [TSLint](https://palantir.github.io/tslint/) configuration files inherit from the workspace-wide `tslint.json`. 工作区中的所有项目都共享这个配置上下文。 每个项目自己的 [TypeScript](https://www.typescriptlang.org/) 配置文件继承自工作区级的 `tsconfig.*.json`,而每个项目自己的 [TSLint](https://palantir.github.io/tslint/) 配置文件也继承自工作区级的 `tslint.json`。 ### Default app project files ### 默认应用工程文件 The CLI command `ng new my-app` creates a workspace folder named "my-app" and generates a new app skeleton. This initial app is the *default app* for CLI commands (unless you change the default after creating additional apps). CLI 命令 `ng new my-app` 创建了一个名叫 "my-app" 的工作区目录,并生成了一个新应用的骨架。 这个初始应用是 CLI 命令的*默认应用*(除非你在创建了其它应用之后修改了默认应用)。 A newly generated app contains the source files for a root module, with a root component and template. 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 initial app. 新生成的应用包含根模块和一个根组件及其模板的代码。 当工作区的文件结构就绪之后,你可以在命令行上运行 `ng generate` 命令,来给这个初始应用添加功能和数据。
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/) 这样的交互开发环境,或者直接操纵应用的源码目录中的源码文件和配置文件。
The `src/` subfolder contains the source files (app logic, data, and assets), along with configuration files for the initial app. Workspace-wide `node_modules` dependencies are visible to this project. `src/` 子目录包含该初始应用的源文件(应用逻辑、数据和资源)以及配置文件。 工作区级的 `node_modules` 依赖,对于这个项目也是可见的。 | APP SOURCE & CONFIG FILES | PURPOSE | | :--------------------- | :------------------------------------------| | 应用源码与配置文件 | 用途 | | `app/` | Contains the component files in which your app logic and data are defined. See details in [App source folder](#app-src) below. | | `app/` | 包含组件文件,其中定义了应用逻辑和数据。详情参见稍后的[应用源码目录](#app-src)。 | | `assets/` | Contains image files 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" 的产品环境。你可以定义一些额外的目标环境配置。 | | `browserslist` | Configures sharing of target browsers and Node.js versions among various front-end tools. See [Browserslist on GitHub](https://github.com/browserslist/browserslist) for more information. | | `browserlist` | 配置各个目标浏览器和 Node.js 版本之间的市场占有率,供各种前端工具使用。详情参见 [GitHub 上的 Browserlist](https://github.com/browserslist/browserslist)。 | | `favicon.ico` | An icon to use for this app 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 `