|
13 | 13 | <a href="https://www.dartlang.org/downloads/">download Dart</a>.
|
14 | 14 | Then return here.
|
15 | 15 |
|
16 |
| -// STEP 1 - Create a project ########################## |
| 16 | +//- STEP 1 - Create a project ########################## |
17 | 17 | .l-main-section
|
18 | 18 | h2#section-install-angular 1. Create a project
|
19 | 19 |
|
|
27 | 27 | > <span class="blk">vim pubspec.yaml</span> # Use your favorite editor!
|
28 | 28 |
|
29 | 29 | p.
|
30 |
| - In <code>pubspec.yaml</code>, add the angular2 and browser packages as dependencies. |
31 |
| - Angular 2 is changing rapidly, so specify an exact version: |
| 30 | + In <code>pubspec.yaml</code>, |
| 31 | + specify the angular2 and browser packages as dependencies, |
| 32 | + as well as the angular2 transformer. |
| 33 | + Angular 2 is changing rapidly, so provide an exact version: |
32 | 34 | <b>2.0.0-alpha.25</b>.
|
33 | 35 |
|
34 |
| - code-example(language="yaml"). |
| 36 | + code-example(language="yaml" format="linenums"). |
35 | 37 | name: hello_world
|
36 | 38 | version: 0.0.1
|
37 | 39 | dependencies:
|
38 | 40 | angular2: 2.0.0-alpha.25
|
39 | 41 | browser: any
|
| 42 | + transformers: |
| 43 | + - angular2: |
| 44 | + entry_points: web/main.dart |
40 | 45 | p.
|
41 | 46 | In the same directory, run <code>pub get</code>
|
42 | 47 | to install the angular2 and browser packages
|
|
45 | 50 | code-example(language="sh").
|
46 | 51 | > <span class="blk">pub get</span>
|
47 | 52 |
|
48 |
| - // PENDING: Create template? Link to pub/pubspec docs? |
49 |
| - // Is browser really needed? |
| 53 | + //- PENDING: browser: any -> ??? |
| 54 | + //- PENDING: Create template? Link to pub/pubspec docs? |
50 | 55 |
|
51 | 56 |
|
52 |
| -// STEP 2 - Import Angular ########################## |
| 57 | +//- STEP 2 - Import Angular ########################## |
53 | 58 | .l-main-section
|
54 | 59 | h2#section-transpile 2. Import Angular
|
55 | 60 |
|
|
70 | 75 | import 'package:angular2/src/reflection/reflection.dart' show reflector;
|
71 | 76 | import 'package:angular2/src/reflection/reflection_capabilities.dart' show ReflectionCapabilities;
|
72 | 77 |
|
73 |
| -// STEP 3 - Define a component ########################## |
| 78 | +//- STEP 3 - Define a component ########################## |
74 | 79 | .l-main-section
|
75 | 80 |
|
76 | 81 | h2#section-angular-create-account 3. Define a component
|
|
143 | 148 | String name = 'Alice';
|
144 | 149 | }
|
145 | 150 |
|
146 |
| -// STEP 4 - Bootstrap ########################## |
| 151 | +//- STEP 4 - Bootstrap ########################## |
147 | 152 | .l-main-section
|
148 | 153 | h2#section-transpile 4. Bootstrap
|
149 | 154 |
|
|
162 | 167 | The argument to <code>bootstrap()</code> is the name of the component class
|
163 | 168 | you defined above.
|
164 | 169 |
|
165 |
| - //- Explain why setting reflector.reflectionCapabilities is necessary. |
166 |
| -
|
167 |
| -
|
168 |
| -// STEP 5 - Declare the HTML ########################## |
| 170 | + p. |
| 171 | + Setting the value of <code>reflector.reflectionCapabilities</code> |
| 172 | + lets your app use the Dart VM's reflection (dart:mirrors) |
| 173 | + when running in Dartium. |
| 174 | + Reflection is fast in native Dart, |
| 175 | + so using it makes sense during development. |
| 176 | + Later, when you build a JavaScript version of your app, |
| 177 | + the Angular transformer will |
| 178 | + convert the reflection-using code to static code, |
| 179 | + so your generated JavaScript can be smaller and faster. |
| 180 | + |
| 181 | + |
| 182 | +//- STEP 5 - Declare the HTML ########################## |
169 | 183 | .l-main-section
|
170 | 184 |
|
171 | 185 | h2#section-angular-create-account 5. Declare the HTML
|
|
175 | 189 | the following code,
|
176 | 190 | which loads <code>main.dart</code> and instantiates the my-app component:
|
177 | 191 |
|
178 |
| - code-example(language="html"). |
| 192 | + code-example(language="html" format="linenums"). |
179 | 193 | <!doctype html>
|
180 | 194 | <html>
|
181 | 195 | <head>
|
|
189 | 203 | </body>
|
190 | 204 | </html>
|
191 | 205 |
|
192 |
| -// STEP 6 - Build and run ########################## |
| 206 | +//- STEP 6 - Run ########################## |
193 | 207 | .l-main-section
|
194 | 208 |
|
195 |
| - h2#section-angular-run-app 6. Build and run your app |
| 209 | + h2#section-angular-run-app 6. Run your app |
196 | 210 |
|
197 | 211 | p.
|
198 | 212 | You have a few options for running your app.
|
|
212 | 226 | you should see <b>Hello Alice</b> in your browser window.
|
213 | 227 |
|
214 | 228 |
|
215 |
| -// STEP 7 - Use the Angular transformer ########################## |
| 229 | +//- STEP 7 - Generate JavaScript ########################## |
216 | 230 | .l-main-section
|
217 | 231 |
|
218 |
| - h2#section-angular-run-app 7. Use the Angular transformer |
219 |
| - |
220 |
| - p. |
221 |
| - To enable quick turnaround while you're developing an Angular app, |
222 |
| - the framework uses reflection via dart:mirrors. |
223 |
| - Unfortunately, mirror-using Dart code compiles to |
224 |
| - JavaScript code that's large and slow. |
225 |
| - To create more deployable JavaScript, use the Angular transformer. |
226 |
| - The transformer analyzes your code, |
227 |
| - converting reflection to static code |
228 |
| - that Dart's build tools can compile to faster, smaller JavaScript. |
229 |
| - |
230 |
| - p. |
231 |
| - To use the Angular transformer, |
232 |
| - first add the highlighted lines to your <code>pubspec.yaml</code>: |
| 232 | + h2#section-angular-run-app 7. Generate JavaScript |
233 | 233 |
|
234 |
| - code-example(language="yaml"). |
235 |
| - name: hello_world |
236 |
| - version: 0.0.1 |
237 |
| - dependencies: |
238 |
| - angular2: 2.0.0-alpha.25 |
239 |
| - browser: any |
240 |
| - <span class="pnk">transformers: |
241 |
| - - angular2: |
242 |
| - entry_points: web/main.dart</span> |
243 | 234 | p.
|
244 |
| - Then build the JavaScript version using <code>pub build</code>: |
| 235 | + Before you can deploy your app, you need to generate JavaScript files. |
| 236 | + Compiling your Dart code to JavaScript is easy: |
| 237 | + just run <code>pub build</code>. |
245 | 238 |
|
246 | 239 | code-example(language="basic").
|
247 | 240 | > <span class="blk">pub build</span>
|
|
254 | 247 | [Info from Dart2JS]:
|
255 | 248 | Took 0:00:16.123086 to compile hello_world|web/main.dart.
|
256 | 249 | Built 41 files to "build".
|
| 250 | + //- REGENERATE THIS OUTPUT - or delete it? - when updating from 2.0.0-alpha.25 |
257 | 251 |
|
258 | 252 | p.
|
259 |
| - The compiled JavaScript appears, along with supporting files, |
| 253 | + The generated JavaScript appears, along with supporting files, |
260 | 254 | under the <code>build</code> directory.
|
261 | 255 |
|
262 | 256 | p.
|
| 257 | + When you generate JavaScript for an Angular app, |
| 258 | + be sure you use the Angular transformer. |
| 259 | + It analyzes your code, |
| 260 | + converting reflection-using code to static code |
| 261 | + that Dart's build tools can compile to faster, smaller JavaScript. |
| 262 | + The highlighted lines in <code>pubspec.yaml</code> |
| 263 | + configure the Angular transformer: |
| 264 | + |
| 265 | + code-example(language="yaml" format="linenums"). |
| 266 | + name: hello_world |
| 267 | + version: 0.0.1 |
| 268 | + dependencies: |
| 269 | + angular2: 2.0.0-alpha.25 |
| 270 | + browser: any |
| 271 | + <span class="pnk">transformers: |
| 272 | + - angular2: |
| 273 | + entry_points: web/main.dart</span> |
| 274 | + p. |
| 275 | + The <code>entry_points</code> entry |
| 276 | + identifies the Dart file in your app |
| 277 | + that has a <code>main()</code> function. |
263 | 278 | For more information, see the
|
264 | 279 | <a href="https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer">Angular
|
265 | 280 | transformer wiki page</a>.
|
266 | 281 |
|
267 |
| -// WHAT'S NEXT... ########################## |
| 282 | +//- WHAT'S NEXT... ########################## |
268 | 283 | .l-main-section
|
269 | 284 | h2#section-transpile Great job! Next step...
|
270 | 285 |
|
|
0 commit comments