Setup a local development environment
搭建本地开发环境
The
Setting up a new project on your machine is quick and easy with the QuickStart seed, maintained on github.
利用 github 上的《快速起步》种子在你的电脑上搭建一个新项目是很快很容易的。
Make sure you have node and npm installed. Then ...
确定你已经安装了 node和npm,然后:
Create a project folder (you can call it
quickstart
and rename it later).新建项目目录(你可以暂时为其取名
quickstart
,以后再重命名)。Clone or download the QuickStart seed into your project folder.
Install npm packages.
安装 npm 包。
Run
npm start
to launch the sample application.运行
npm start
来启动例子应用。
Clone
克隆
Perform the clone-to-launch steps with these terminal commands.
运行下列命令来执行克隆并启动步骤。
npm start
fails in Bash for Windows which does not support networking to servers as of January, 2017.
在Bash for Windows中npm start
可能会失败,因为到2017-01为止它还不支持访问网络上的服务器。
Download
下载
Download the QuickStart seed and unzip it into your project folder. Then perform the remaining steps with these terminal commands.
下载《快速起步》种子 并解压到你的项目目录中。然后执行下面的命令完成剩余步骤。
npm start
fails in Bash for Windows which does not support networking to servers as of January, 2017.
在Bash for Windows中npm start
可能会失败,因为到2017-01为止它还不支持访问网络上的服务器。
Delete non-essential files (optional)
删除非必需文件(可选)
You can quickly delete the non-essential files that concern testing and QuickStart repository maintenance
(including all git-related artifacts such as the .git
folder and .gitignore
!).
你可以快速删除一些涉及到测试和维护快速开始版本库的 非必需 文件
(包括所有git相关的文件如 .git
文件夹和 .gitignore
!)。
Do this only in the beginning to avoid accidentally deleting your own tests and git setup!
请只在开始时执行此删除操作,以防你自己的测试和git文件被意外删除!
Open a terminal window in the project folder and enter the following commands for your environment:
在项目目录下打开一个终端窗口,并根据你的操作系统执行以下命令:
OS/X (bash)
Windows
What's in the QuickStart seed?
《快速起步》种子库里都有什么?
The QuickStart seed contains the same application as the QuickStart playground. But its true purpose is to provide a solid foundation for local development. Consequently, there are many more files in the project folder on your machine, most of which you can learn about later.
《快速起步》种子 包含了与《快速起步》游乐场一样的应用,但是,它真正的目的是提供坚实的本地开发基础。 所以你的电脑里的项目目录里面有更多文件,参见搭建剖析。
Focus on the following three TypeScript (.ts
) files in the /src
folder.
注意/src
目录中以下三个 TypeScript (.ts
) 文件:
All guides and cookbooks have at least these core files. Each file has a distinct purpose and evolves independently as the application grows.
所有指南和烹饪书都至少有这几个核心文件。每个文件都有独特的用途,并且随着应用的成长各自独立演变。
Files outside src/
concern building, deploying, and testing your app.
They include configuration files and external dependencies.
src/
目录之外的文件为构建、部署和测试app相关的文件,他们只包括配置文件和外部依赖。
Files inside src/
"belong" to your app.
Add new Typescript, HTML and CSS files inside the src/
directory, most of them inside src/app
,
unless told to do otherwise.
src/
目录下的文件才“属于”你的app。
除非明确指出,否则教程中添加的 TypeScript,HTML和CSS文件都在src/
目录下,
大多数在src/app
目录中。
The following are all in src/
src/
目录文件详情如下:
File 文件 | Purpose 用途 |
---|---|
app/app.component.ts | Defines the same 定义与《快速起步》游乐场同样的 |
app/app.module.ts | Defines 定义 |
main.ts | Compiles the application with the JIT compiler and
bootstraps
the application's main module ( 使即时 (JiT) 编译器用编译应用并且在浏览器中启动并运行应用。 对于大多数项目的开发,这都是合理的选择。而且它是在像 Plunker 这样的在线编程环境中运行例子的唯一选择。 你将在本文档中学习其他编译和开发选择。 |
Next Step
下一步
If you're new to Angular, we recommend staying on the learning path.
如果你是 Angular 初学者,建议根据学习路径学习。
Appendix: node and npm
附录:node 与 npm
Node.js and npm are essential to modern web development with Angular and other platforms. Node powers client development and build tools. The npm package manager, itself a node application, installs JavaScript libraries.
Node.js 和 npm 对使用 Angular 和其他平台进行现代网络开发是至关重要的。 Node 驱动客户端开发和构建工具。 npm 包管理器本身是 node 应用,用于安装 JavaScript 库。
Get them now if they're not already installed on your machine.
如果你的电脑没有安装它们, 立刻安装它们。
Verify that you are running node v4.x.x
or higher and npm 3.x.x
or higher
by running the commands node -v
and npm -v
in a terminal/console window.
Older versions produce errors.
在终端/控制器窗口运行命令node -v
和npm -v
,来确认你运行的 node 是v4.x.x
或更高,npm 为3.x.x
或更高。
老版本会产生错误。
We recommend nvm for managing multiple versions of node and npm. You may need nvm if you already have projects running on your machine that use other versions of node and npm.
我们推荐使用 nvm 来管理多版本 node 和 npm。 如果你的电脑上已经有使用其他版本 node 和 npm 的项目,你可能需要 nvm。
Appendix: Why develop locally
附录:为何在本地开发
在浏览器中
Links on almost every documentation page open completed samples in the browser. You can play with the sample code, share your changes with friends, and download and run the code on your own machine.
几乎每章文档里面的链接都在浏览器中打开完整的例子。 你可以用这些代码做实验,或者与朋友共享你的修改,或者下载并在你自己的电脑上运行这些代码。
The QuickStart shows just the AppComponent
file.
It creates the equivalent of app.module.ts
and main.ts
internally for the playground only.
so the reader can discover Angular without distraction.
The other samples are based on the QuickStart seed.
快速起步仅仅展示了AppComponent
文件。
它在内部创建了只为游乐场而准备的等价app.module.ts
和main.ts
。
所以读者可以在零干扰的情况下探索 Angular。
其他例子是基于 《快速起步》种子的。
As much fun as this is ...
虽然有这么多的乐趣,但是...
you can't ship your app in plunker
你不能在 plunker 里面发布你的应用
you aren't always online when writing code
编程时你不可能总是在线
transpiling TypeScript in the browser is slow
在浏览器中编译 TypeScript 很慢
the type support, refactoring, and code completion only work in your local IDE
只有本地 IDE 有类型支持、代码重构和代码自动完成
Use the
把
For real development, we strongly recommend developing locally.
对于现实项目开发,我们强烈推荐在本地开发。