You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/documentation/stories/universal-rendering.md
+16-54Lines changed: 16 additions & 54 deletions
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ This example places it alongside `app.module.ts` in a file named `app.server.mod
57
57
58
58
You can see here we're simply Importing everything from AppModule, followed by ServerModule.
59
59
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 AngularCLI.
61
61
62
62
```typescript
63
63
import {NgModule} from'@angular/core';
@@ -122,72 +122,34 @@ Add a section for `"angularCompilerOptions"` and set `"entryModule"` to your `Ap
122
122
```
123
123
124
124
---
125
-
## Step 3: Create a new project in `.angular-cli.json`
125
+
## Step 3: Create a new target in `angular.json`
126
126
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:
132
129
133
130
```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.
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`:
182
147
183
148
```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
0 commit comments