Skip to content

Commit e65a885

Browse files
filipesilvahansl
authored andcommitted
docs: update universal doc
1 parent e997a25 commit e65a885

File tree

1 file changed

+16
-54
lines changed

1 file changed

+16
-54
lines changed

docs/documentation/stories/universal-rendering.md

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ This example places it alongside `app.module.ts` in a file named `app.server.mod
5757

5858
You can see here we're simply Importing everything from AppModule, followed by ServerModule.
5959

60-
> One important thing to Note: We need `ModuleMapLoaderModule` to help make Lazy-loaded routes possible during Server-side renders with the Angular-CLI.
60+
> One important thing to Note: We need `ModuleMapLoaderModule` to help make Lazy-loaded routes possible during Server-side renders with the Angular CLI.
6161
6262
```typescript
6363
import {NgModule} from '@angular/core';
@@ -122,72 +122,34 @@ Add a section for `"angularCompilerOptions"` and set `"entryModule"` to your `Ap
122122
```
123123

124124
---
125-
## Step 3: Create a new project in `.angular-cli.json`
125+
## Step 3: Create a new target in `angular.json`
126126

127-
In `.angular-cli.json` there is an array under the key `"apps"`. Copy the configuration for your client application there, and paste it as a new entry in the array, with an additional key `"platform"` set to `"server"`.
128-
129-
Then, remove the `"polyfills"` key - those aren't needed on the server, and adjust `"main"`, and `"tsconfig"` to point to the files you wrote in step 2. Finally, adjust `"outDir"` to a new location (this example uses `dist-server`).
130-
131-
### .angular-cli.json:
127+
In `angular.json` locate the `architect` property inside your project, and add a new `server`
128+
target:
132129

133130
```javascript
134-
{
135-
...
136-
"apps": [
137-
{
138-
// Keep your original application config intact here, this is app 0
139-
// -EXCEPT- for outDir, update it to dist/browser
140-
"outDir": "dist/browser" // <-- update this
141-
},
142-
{
143-
// This is your server app. It is app 1.
144-
"platform": "server",
145-
"root": "src",
146-
// Build to dist/server instead of dist. This prevents
147-
// client and server builds from overwriting each other.
148-
"outDir": "dist/server",
149-
"assets": [
150-
"assets",
151-
"favicon.ico"
152-
],
153-
"index": "index.html",
154-
// Change the main file to point to your server main.
155-
"main": "main.server.ts",
156-
// Remove polyfills.
157-
// "polyfills": "polyfills.ts",
158-
"test": "test.ts",
159-
// Change the tsconfig to point to your server config.
160-
"tsconfig": "tsconfig.server.json",
161-
"testTsconfig": "tsconfig.spec.json",
162-
"prefix": "app",
163-
"styles": [
164-
"styles.css"
165-
],
166-
"scripts": [],
167-
"environmentSource": "environments/environment.ts",
168-
"environments": {
169-
"dev": "environments/environment.ts",
170-
"prod": "environments/environment.prod.ts"
171-
}
131+
"architect": {
132+
"build": { ... }
133+
"server": {
134+
"builder": "@angular-devkit/build-angular:server",
135+
"options": {
136+
"outputPath": "dist/your-project-name-server",
137+
"main": "src/main.server.ts",
138+
"tsConfig": "src/tsconfig.server.json"
172139
}
173-
],
174-
...
140+
}
175141
}
176-
177142
```
178143

179144
## Building the bundle
180145

181146
With these steps complete, you should be able to build a server bundle for your application, using the `--app` flag to tell the CLI to build the server bundle, referencing its index of `1` in the `"apps"` array in `.angular-cli.json`:
182147

183148
```bash
184-
# This builds the client application in dist/browser/
185-
$ ng build --prod
186-
...
187-
# This builds the server bundle in dist/server/
188-
$ ng build --prod --app 1 --output-hashing=false
149+
# This builds your project using the server target, and places the output
150+
# in dist/your-project-name-server/
151+
$ ng run your-project-name:server
189152

190-
# outputs:
191153
Date: 2017-07-24T22:42:09.739Z
192154
Hash: 9cac7d8e9434007fd8da
193155
Time: 4933ms

0 commit comments

Comments
 (0)