Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AoT): Enable AoT with Lazy Loading. Enable Angular CLI support.
Enables AoT compilation support and better Lazy Loading support. When `@ngtools/webpack` is being used, this also enables automatic code splitting + lazy loading. Because `angular-cli` uses `@ngtools/webpack`, this change also enables `angular-cli` support. To use the new feature, define a `Future State` (by appending `.**` to the state name). Give the state a `loadChildren` property which points to a nested NgModule that will be lazy loaded. Use the same syntax that `@ngtools/webpack` expects: `<pathToModule>#<name of export>`. ```js export var futureFooState = { name: 'foo.**', url: '/foo', loadChildren: './foo/foo.module#FooModule' }; ... imports: [ UIRouterModule.forRoot({ states: [ futureFooState ] }), ... ``` In your nested module, add a state named `foo` (without the `.**`). This nested module's `foo` state will replace the `foo.**` Future State (placeholder). ```js export var fooState = { name: 'foo', url: '/foo', resolve: { fooData: fooResolveFn }, onEnter: onEnterFooFn, data: { requiresAuth: true } }; ... imports: [ UIRouterModule.forChild({ states: [ fooState ] }), ... ``` This change works by providing the same DI token as the `@angular/router` which is then analyzed for lazy loading by `@ngtools/webpack`. The `ROUTES` token is deep imported from `@angular/router/src/router_config_loader`. The module's states are provided on the ROUTES token, which enables the webpack tooling to analyze the states, looking for `loadChildren`. When the UMD bundle is built, the ROUTES token is pulled in from `@angular/router` (and duplicated), but should not be used by anything. Because we pull in the token from the `@angular/router` package, we have a temporary dependency on the angular router. This is a temporary hack until the `@ngtools/webpack` project makes itself router-agnostic.
- Loading branch information