Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 2da280c

Browse files
committed
docs(prod-deploy): overview and next steps
1 parent 8faf666 commit 2da280c

File tree

1 file changed

+73
-33
lines changed

1 file changed

+73
-33
lines changed

public/docs/ts/latest/guide/production-deploy.jade

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ include ../_util-fns
66
a#toc
77
:marked
88
## Table of contents
9-
* [Simplest deployment possible](#simplest-deployment-possible)
9+
* [Overview](#overview)
10+
* [Simplest deployment possible](#dev-deploy)
1011
* [Optimize for production](#optimize)
1112
* [Ahead-of-Time (AOT) compilation](#aot)
1213
* [Webpack](#webpack)
@@ -16,39 +17,66 @@ a#toc
1617
* [The `base` tag](#base-tag)
1718
* [Enable production mode](#enableprodmode)
1819
* [Lazy loading](#lazy-loading)
19-
* [Server configuration for routed apps](#server-configuration)
20-
* [Why fallback to `index.html`?](#why-fallback-to-index-html-)
21-
* [Fallback configuration examples](#fallback-configuration-examples)
22-
* [Requesting services from a different server (CORS)](#cors)
20+
* [Server configuration](#server-configuration)
21+
* [Routed apps must fallback to `index.html`](#fallback)
22+
* [CORS: requesting services from a different server](#cors)
2323

24+
a#overview
2425
.l-main-section
26+
:marked
27+
## Overview
28+
29+
This guide describes techniques for preparing and deploying an Angular application to a server running remotely.
30+
The techniques progress from _easy but suboptimal_ to _more optimal and more involved_.
31+
32+
* The [simple way](#dev-deploy "Simplest deployment possible") is to copy the development environment to the server.
33+
34+
* [_Ahead of Time_ compilation (AOT)](#aot "AOT Compilation") is the first of
35+
[several optimization strategies](#optimize).
36+
You'll also want to read the [detailed instructions in the AOT Cookbook](aot-compiler.html "AOT Cookbook").
37+
38+
* [Webpack](#webpack "Webpack Optimization") is a popular general purpose packaging tool with a rich ecosystem, including plugins for AOT.
39+
The Angular [webpack guide](webpack.html "Webpack: an introduction") can get you started and
40+
_this_ page provides additional optimization advice, but you'll probably have to learn more about webpack on your own.
41+
42+
* The [Angular configuration](#angular-configuration "Angular configuration") section calls attention to
43+
specific client application changes that could improve performance.
44+
45+
* The [Server configuration](#server-configuration "Server configuration") section describes
46+
server-side changes that may be necessary, _no matter how you deploy the application_.
47+
48+
.l-main-section
49+
a#dev-deploy
2550
:marked
2651
## Simplest deployment possible
2752

28-
The simplest way to deploy your app is to publish it to a web server
29-
directly out of your development environment.
30-
It's already running locally. You're just moving it, almost _as is_,
31-
to a server others can reach.
53+
The simplest way to deploy the app is to publish it to a web server
54+
directly out of the development environment.
55+
It's already running locally. You're just copying it, almost _as is_,
56+
to a non-local server that others can reach.
3257

33-
1. Copy _everything_ in your local project folder into a folder on your server.
58+
1. Copy _everything_ (or [_almost_ everything](#node-modules "Loading npm packages from the web"))
59+
from the local project folder to a folder on the server.
3460

35-
2. If you're serving the app out of a subfolder,
61+
1. If you're serving the app out of a subfolder,
3662
edit a version of `index.html` to set the `<base href>` appropriately.
3763
For example, if the URL to `index.html` is `www.mysite.com/myapp/`, set the _base href_ to
3864
`<base href="/myapp/">`.
3965
Otherwise, leave it alone.
4066
[More on this below](#base-tag).
4167

42-
3. Configure your server to redirect requests for missing files to `index.html` instead.
43-
[More on this below](#server-configuration).
68+
1. Configure the server to redirect requests for missing files to `index.html`.
69+
[More on this below](#fallback).
4470

45-
4. Enable production mode as [described below](#enableprodmode) (optional).
71+
1. Enable production mode as [described below](#enableprodmode) (optional).
4672

4773
That's all it takes to publish your app!
4874

49-
### Load third-party packages from the web (SystemJS)
75+
a#node-modules
76+
:marked
77+
### Load npm packages from the web (SystemJS)
5078

51-
The `node_modules` folder is huge and slow to upload to the server.
79+
The `node_modules` folder of _npm packages_ is huge and slow to upload to the server.
5280
It's typically 20,500+ files and 180+ MB.
5381
The application itself requires a tiny fraction of that to run.
5482

@@ -63,7 +91,7 @@ a#toc
6391
loads `systemjs.config.server.js`.
6492
+makeExample('index.html', 'systemjs-config', '')(format=".")
6593
:marked
66-
(3) Add `systemjs.config.server.js` (shown in the code sample below) to your root folder.
94+
(3) Add `systemjs.config.server.js` (shown in the code sample below) to the root folder.
6795
This alternative version configures _SystemJS_ to load _UMD_ versions of Angular
6896
(and other third-party packages) from the web.
6997

@@ -126,7 +154,7 @@ a#toc
126154
(although you wouldn't be able to recompile or launch `lite-server`
127155
until you restored it).
128156

129-
1. Deploy the sample to your server (minus the `node_modules` folder!).
157+
1. Deploy the sample to the server (minus the `node_modules` folder!).
130158

131159
When you have that working, try the same process on your application.
132160

@@ -147,7 +175,7 @@ a#optimize
147175
can be significantly larger than is strictly necessary to execute the application.
148176

149177
The many requests and large payloads mean
150-
your app takes longer to launch than it would if you optimized it.
178+
the app takes longer to launch than it would if you optimized it.
151179
Several seconds may pass (or worse) before the user can see or do anything userful.
152180

153181
Does it matter? That depends upon business and technical factors you must evaluate for yourself.
@@ -183,7 +211,7 @@ a#aot
183211
* You don't download the Angular compiler, which is pretty big on its own.
184212
* The compiler discards unused Angular directives that a tree-shaking tool can then exclude.
185213

186-
Learn more about AOT Compilation in the [AOT Cookbook](AOT-compiler.html "AOT Cookbook")
214+
Learn more about AOT Compilation in the [AOT Cookbook](aot-compiler.html "AOT Cookbook")
187215
which describes running the AOT compiler from the command line
188216
and using [_rollup_](#rollup) for bundling, minification, uglification and tree shaking.
189217

@@ -193,6 +221,8 @@ a#webpack
193221

194222
<a href="https://webpack.js.org/" target="_blank" title="Webpack 2">Webpack 2</a> is another
195223
great option for inlining templates and style-sheets, for bundling, minifying, and uglifying the application.
224+
The "[Webpack: an introduction](webpack.html "Webpack: an introduction")" guide will get you started
225+
using webpack with Angular.
196226

197227
Consider configuring _Webpack_ with the official
198228
<a href="https://github.com/angular/angular-cli/tree/master/packages/%40ngtools/webpack" target="_blank" title="Ahead-of-Time Webpack Plugin">
@@ -220,7 +250,7 @@ a#measure
220250
### Measure performance first
221251

222252
You can make better decisions about what to optimize and how when you have a clear and accurate understanding of
223-
what's making your application slow.
253+
what's making the application slow.
224254
The cause may not be what you think it is.
225255
You can waste a lot of time and money optimizing something that has no tangible benefit or even makes the app slower.
226256
You should measure the app's actual behavior when running in the environments that are important to you.
@@ -234,7 +264,7 @@ a#angular-configuration
234264
:marked
235265
## Angular configuration
236266

237-
Angular configuration can make the difference between whether your app launches quickly or doesn't load at all.
267+
Angular configuration can make the difference between whether the app launches quickly or doesn't load at all.
238268

239269
a#base-tag
240270
:marked
@@ -251,13 +281,13 @@ a#base-tag
251281
See also the [*APP_BASE_HREF*](../api/common/index/APP_BASE_HREF-let.html "API: APP_BASE_HREF") alternative.
252282
:marked
253283
In development, you typically start the server in the folder that holds `index.html`.
254-
That's your root folder and you'd add `<base href="/">` near the top of `index.html` because `/` is the root of your app.
284+
That's the root folder and you'd add `<base href="/">` near the top of `index.html` because `/` is the root of the app.
255285

256-
But on your shared or production server, you might serve the app from a subfolder.
286+
But on the shared or production server, you might serve the app from a subfolder.
257287
For example, when the URL to load the app is something like `http://www.mysite.com/myapp/`,
258288
the subfolder is `myapp/` and you should add `<base href="/myapp/">` to the server version of the `index.html`.
259289

260-
When your `base` tag is misconfigured, the app fails to load and the browser console displays `404 - Not Found` errors
290+
When the `base` tag is misconfigured, the app fails to load and the browser console displays `404 - Not Found` errors
261291
for the missing files. Look at where it _tried_ to find those files and adjust the base tag appropriately.
262292

263293
a#enableProdMode
@@ -296,7 +326,7 @@ a#lazy-loading
296326
in a file that's eagerly loaded when the app starts, a file such as the root `AppModule`.
297327
If you do that, the module will be loaded immediately.
298328

299-
Your bundling configuration must take lazy loading into consideration.
329+
The bundling configuration must take lazy loading into consideration.
300330
Because lazy loaded modules aren't imported in JavaScript (as just noted), bundlers exclude them by default.
301331
Bundlers don't know about the router configuration and won't create separate bundles for lazy loaded modules.
302332
You have to create these bundles manually.
@@ -309,17 +339,20 @@ a#lazy-loading
309339
a#server-configuration
310340
.l-main-section
311341
:marked
312-
## Server configuration for routed apps
342+
## Server configuration
343+
344+
This section covers changes you may have make to the server or to files deployed to the server.
345+
346+
a#fallback
347+
### Routed apps must fallback to `index.html`
313348

314349
Angular apps are perfect candidates for serving with a simple static HTML server.
315350
You don't need a server-side engine to dynamically compose application pages because
316351
Angular does that on the client-side.
317352

318-
If your app uses the Angular router, you must configure the server
353+
If the app uses the Angular router, you must configure the server
319354
to return the application's host page (`index.html`) when asked for a file that it does not have.
320355

321-
### Why fallback to `index.html`?
322-
323356
a#deep-link
324357
:marked
325358
A routed application should support "deep links".
@@ -339,7 +372,7 @@ a#deep-link
339372
But it rejects `http://www.mysite.com/heroes/42` and returns a `404 - Not Found` error *unless* it is
340373
configured to return `index.html` instead.
341374

342-
### Fallback configuration examples
375+
#### Fallback configuration examples
343376

344377
There is no single configuration that works for every server.
345378
The following sections describe configurations for some of the most popular servers.
@@ -434,7 +467,14 @@ a#cors
434467
to a server other than the application's own host server.
435468
Browsers forbid such requests unless the server permits them explicitly.
436469

437-
There isn't anything your client application can do about these errors.
438-
The server must be configured to accept your application's requests.
470+
There isn't anything the client application can do about these errors.
471+
The server must be configured to accept the application's requests.
439472
Read about how to enable CORS for specific servers at
440473
<a href="http://enable-cors.org/server.html" target="_blank" title="Enabling CORS server">enable-cors.org</a>.
474+
475+
a#next-steps
476+
.l-main-section
477+
:marked
478+
## Next steps
479+
If you want to go beyond the [simple _copy-deploy_](#dev-deploy "Simplest deployment possible") approach,
480+
read the [AOT Cookbook](aot-compiler.html "AOT Cookbook") next.

0 commit comments

Comments
 (0)