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
docs: Update Universal Story to include module map
@nguniversal/module-map-ngfactory-loader has been release and with it, support for Lazy loading!
This PR updates the existing story to guide users how they can use this functionality.
## Step 2: Prepare your app for Universal rendering
21
30
22
31
The first thing you need to do is make your `AppModule` compatible with Universal by addding `.withServerTransition()` and an application ID to your `BrowserModule` import:
23
32
@@ -49,6 +58,7 @@ This example places it alongside `app.module.ts` in a file named `app.server.mod
@@ -59,6 +69,7 @@ import {AppComponent} from './app.component';
59
69
// by the ServerModule from @angular/platform-server.
60
70
AppModule,
61
71
ServerModule,
72
+
ModuleMapLoaderModule
62
73
],
63
74
// Since the bootstrapped component is not inherited from your
64
75
// imported AppModule, it needs to be repeated here.
@@ -67,13 +78,20 @@ import {AppComponent} from './app.component';
67
78
exportclassAppServerModule {}
68
79
```
69
80
70
-
## Step 2: Create a server main file and tsconfig to build it
81
+
## Step 3: Create a server main file and tsconfig to build it
71
82
72
-
Create a main file for your Universal bundle. This file only needs to export your `AppServerModule`. It can go in `src`. This example calls this file `main.server.ts`:
83
+
Create a main file for your Universal bundle. This file exports your `AppServerModule` and enables production mode if build target is set to production. It can go in `src`. This example calls this file `main.server.ts`:
@@ -105,7 +123,7 @@ Add a section for `"angularCompilerOptions"` and set `"entryModule"` to your `Ap
105
123
}
106
124
```
107
125
108
-
## Step 3: Create a new project in `.angular-cli.json`
126
+
## Step 4: Create a new project in `.angular-cli.json`
109
127
110
128
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"`.
111
129
@@ -166,8 +184,8 @@ With these steps complete, you should be able to build a server bundle for your
166
184
# This builds the client application in dist/
167
185
$ ng build --prod
168
186
...
169
-
# This builds the server bundle in dist-server/
170
-
$ ng build --prod --app 1
187
+
# This builds the server bundle in dist-server/ and disables output hashing
After pre rendering the application with `renderModuleFactory` we can now serve the application, to do this create a server.js file within the dist folder
* Lazy loading is not yet supported, but coming very soon. Currently lazy loaded routes aren't available for prerendering, and you will get a `System is not defined` error.
203
-
* The bundle produced has a hash in the filename from webpack. When deploying this to a production server, you will need to ensure the correct bundle is required, either by renaming the file or passing the bundle name as an argument to your server.
299
+
* The bundle produced has a hash in the filename from webpack. When deploying this to a production server, you will need to ensure the correct bundle is required, either by renaming the file or passing the bundle name as an argument to your server.
0 commit comments