@@ -13,30 +13,31 @@ block setup-tooling
13
13
:marked
14
14
Install the **[Dart SDK](https://www.dartlang.org/downloads/)**,
15
15
if not already on your machine, and any tools you like to use with Dart.
16
- The Dart SDK includes **[pub][pub]**, the Dart package manager, that we
17
- will be using shortly.
16
+ The Dart SDK includes tools such as **[pub][pub]**, the Dart package manager.
18
17
If you don't have a favorite Dart editor already, try
19
18
[WebStorm][WS], which comes with a Dart plugin.
20
19
You can also download [Dart plugins for other IDEs and editors][DT].
21
20
22
21
[WS]: https://confluence.jetbrains.com/display/WI/Getting+started+with+Dart
23
22
[DT]: https://www.dartlang.org/tools
24
23
[pub]: https://www.dartlang.org/tools/pub
25
-
24
+
26
25
block download-source
27
26
// exclude this section from Dart
28
27
29
28
block package-and-config-files
30
29
:marked
31
- In the project folder just created, put a file named
32
- **[pubspec.yaml][pubspec]** in it.
33
- As shown below, in `pubspec.yaml`, specify the angular2 and browser
34
- packages as dependencies, as well as the angular2 transformer.
30
+ In the project folder just created, create a file named
31
+ **[pubspec.yaml][pubspec]** with the code below.
32
+ This pubspec must specify the **angular2** and **browser**
33
+ packages as dependencies, as well as the `angular2` transformer.
34
+ It can also specify other packages and transformers for the app to use,
35
+ such as [dart_to_js_script_rewriter](https://pub.dartlang.org/packages/dart_to_js_script_rewriter).
35
36
Angular 2 is still changing, so provide an exact version: **2.0.0-beta.17**.
36
37
37
38
[pubspec]: https://www.dartlang.org/tools/pub/pubspec.html
38
39
39
- + makeExample('quickstart/dart/pubspec.yaml' , 'no-rewriter' , 'pubspec.yaml' )
40
+ + makeExample('quickstart/dart/pubspec.yaml' , null , 'pubspec.yaml' )
40
41
41
42
block install-packages
42
43
:marked
@@ -57,69 +58,58 @@ block create-main
57
58
Now we need something to tell Angular to load the root component.
58
59
Create:
59
60
ul
60
- li a #[ b folder named #[ code web] ] , and inside it
61
- li the file #[ code #[ + adjExPath('app/main.ts' )] ] with the following content:
61
+ li a #[ b folder named #[ code web] ]
62
+ li a < b > file named #[code #[+adjExPath('app/main.ts')]]</ b > with the following content:
62
63
63
64
block index-html-commentary-for-ts
64
65
//- N/A
65
66
66
67
block run-app
67
68
p.
68
- You have a few options for running your app.
69
+ We have a few options for running our app.
69
70
One is to launch a local HTTP server
70
71
and then view the app in
71
72
<a href =" https://www.dartlang.org/tools/dartium/" >Dartium</a >.
72
- You can use whatever server you like , such as WebStorm's server
73
+ We can use any web server , such as WebStorm's server
73
74
or Python's SimpleHTTPServer.
74
75
p.
75
76
Another option is to build and serve the app using <code >pub serve</code >,
76
77
and then run it by visiting <b ><code >http://localhost:8080</code ></b > in any modern browser.
77
78
Pub serve generates JavaScript on the fly,
78
- which can take a while when you first visit the page.
79
- Pub serve also runs in <b ><i >watch mode</i ></b >, and will re-compile and subsequently serve
80
- and changed assets.
79
+ which can take a while when first visiting the page.
80
+ Pub serve also runs in <b ><i >watch mode</i ></b >, and will recompile and subsequently serve
81
+ any changed assets.
81
82
p.
82
- Once the app is running, you should see the following in your browser
83
- window:
83
+ Once the app is running, the browser window should show the following:
84
84
85
85
block build-app
86
86
.alert.is-important
87
87
:marked
88
- If you don't see that , make sure you've entered all the code correctly,
88
+ If you don't see **My First Angular 2 App** , make sure you've entered all the code correctly,
89
89
in the [proper folders](#wrap-up),
90
90
and run `pub get`.
91
91
92
92
.l-verbose-section
93
93
h3#section-angular-run-app Building the app (generating JavaScript)
94
94
95
95
:marked
96
- Before you can deploy your app, you need to generate JavaScript files.
96
+ Before deploying the app, we need to generate JavaScript files.
97
97
The `pub build` command makes that easy.
98
- To improve your app's performance, convert the
99
- HTML file to directly include the generated JavaScript;
100
- one way to do that is with `dart_to_js_script_rewriter`.
101
-
102
- Add the `dart_to_js_script_rewriter` package to your pubspec,
103
- in both the `dependencies` and `transformers` sections.
104
-
105
- - var stylePattern = { pnk: / (dart_to_js_script_rewriter. * $ )| (- dart_to_js_script_rewriter. * $ )/ gm , otl: / (dependencies:)| (transformers:)/ g };
106
- + makeExample('quickstart/dart/pubspec.yaml' , null , 'pubspec.yaml' , stylePattern)
107
-
108
- p.
109
- Then compile your Dart code to JavaScript,
110
- using <code >pub build</code >.
111
98
112
99
code-example( language ="sh" ) .
113
100
> <span class =" blk" >pub build</span >
114
101
Loading source assets...
115
102
116
103
p.
117
104
The generated JavaScript appears, along with supporting files,
118
- under the <code >build</code > directory.
105
+ under a directory named <code >build</code >.
106
+
107
+ h4#angular_transformer Using the Angular transformer
108
+
119
109
p.
120
- When you generate JavaScript for an Angular app,
110
+ When generating JavaScript for an Angular app,
121
111
be sure to use the Angular transformer.
122
- It analyzes your code,
112
+ It analyzes the Dart code,
123
113
converting reflection-using code to static code
124
114
that Dart's build tools can compile to faster, smaller JavaScript.
125
115
The highlighted lines in <code >pubspec.yaml</code >
@@ -130,7 +120,7 @@ block build-app
130
120
131
121
p.
132
122
The <code >entry_points</code > item
133
- identifies the Dart file in your app
123
+ identifies the Dart file in our app
134
124
that has a <code >main()</code > function.
135
125
For more information, see the
136
126
<a href =" https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer" >Angular
@@ -139,39 +129,69 @@ block build-app
139
129
#performance .l-sub-section
140
130
h3 Performance, the transformer, and Angular 2 libraries
141
131
p.
142
- When you import <code >bootstrap.dart</code >,
143
- you also get <code >dart:mirrors</code >,
132
+ When an app imports <code >bootstrap.dart</code >,
133
+ it also gets <code >dart:mirrors</code >,
144
134
a reflection library that
145
135
causes performance problems when compiled to JavaScript.
146
136
Don't worry,
147
- the Angular transformer converts your entry points
137
+ the Angular transformer converts the app's entry points
148
138
(<code >entry_points</code > in <code >pubspec.yaml</code >)
149
139
so that they don't use mirrors.
150
140
151
- block server-watching
141
+ h4#dart_to_js_script_rewriter Using dart_to_js_script_rewriter
142
+
143
+ :marked
144
+ To improve the app's performance, convert the
145
+ HTML file to directly include the generated JavaScript;
146
+ one way to do that is with `dart_to_js_script_rewriter`.
147
+ To use the rewriter, specify `dart_to_js_script_rewriter` in both
148
+ the `dependencies` and `transformers` sections of the pubspec.
149
+
150
+ - var stylePattern = { otl: / (dart_to_js_script_rewriter. * $ )| (- dart_to_js_script_rewriter. * $ )| (dependencies:)| (transformers:)/ gm };
151
+ + makeExample('quickstart/dart/pubspec.yaml' , null , 'pubspec.yaml' , stylePattern)
152
+
153
+ .alert.is-important
154
+ :marked
155
+ The `dart_to_js_script_rewriter` transformer must be
156
+ **after** the `angular2` transformer in `pubspec.yaml`.
157
+
158
+ :marked
159
+ For more information, see the docs for
160
+ [dart_to_js_script_rewriter](https://pub.dartlang.org/packages/dart_to_js_script_rewriter).
161
+
162
+ block server-watching
152
163
:marked
153
- Pub serve is watching and
154
- should detect the change, recompile the Dart into JavaScript,
155
- refresh the browser, and display the revised message.
156
- It's a nifty way to develop an application!
164
+ To see the new version, just reload the page.
157
165
158
- Ensure that you terminate the `pub serve` process once you are done.
166
+ .alert.is-important
167
+ :marked
168
+ Be sure to terminate the `pub serve` process once you stop working on this app.
159
169
160
170
block project-file-structure
161
171
.filetree
162
172
.file angular2-quickstart
163
173
.children
164
- .file build ...
165
174
.file lib
166
175
.children
167
176
.file app_component.dart
168
177
.file pubspec.yaml
169
178
.file web
170
179
.children
171
180
.file index.html
172
- .file main.ts
181
+ .file main.dart
173
182
.file styles.css
174
183
184
+ .l-verbose-section
185
+ :marked
186
+ This figure doesn't show generated files and directories.
187
+ For example, a `pubspec.lock` file
188
+ specifies versions and other identifying information for
189
+ the packages that our app depends on.
190
+ The `pub build` command creates a `build` directory
191
+ containing the JavaScript version of our app.
192
+ Pub, IDEs, and other tools often create
193
+ other directories and dotfiles.
194
+
175
195
block project-files
176
196
+ makeTabs(`
177
197
quickstart/ts/app/app.component.ts,
@@ -180,10 +200,10 @@ block project-files
180
200
quickstart/dart/pubspec.yaml,
181
201
quickstart/ts/styles.1.css`
182
202
,null ,
183
- ` app/app.component.ts,
184
- app/main.ts,
203
+ ` app/app.component.ts,
204
+ app/main.ts,
185
205
index.html,
186
- pubspec.yaml,
206
+ pubspec.yaml,
187
207
styles.css` )
188
208
189
209
block what-next-ts-overhead
0 commit comments