Skip to content

Commit

Permalink
feat(nx): use dynamic imports for lazy-loading
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored and vsavkin committed May 22, 2019
1 parent 416ba04 commit d72db4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
25 changes: 19 additions & 6 deletions packages/angular/src/schematics/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ describe('lib', () => {
expect(moduleContents).toContain(`
{
path: 'my-dir-my-lib',
loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule'
loadChildren: () =>
import('@proj/my-dir/my-lib').then(module => module.MyDirMyLibModule)
}`);

const tsConfigAppJson = JSON.parse(
Expand Down Expand Up @@ -516,12 +517,16 @@ describe('lib', () => {
expect(moduleContents2).toContain(`
{
path: 'my-dir-my-lib',
loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule'
loadChildren: () =>
import('@proj/my-dir/my-lib').then(module => module.MyDirMyLibModule)
}`);
expect(moduleContents2).toContain(`
{
path: 'my-dir-my-lib2',
loadChildren: '@proj/my-dir/my-lib2#MyDirMyLib2Module'
loadChildren: () =>
import('@proj/my-dir/my-lib2').then(
module => module.MyDirMyLib2Module
)
}`);

const tsConfigAppJson2 = JSON.parse(
Expand Down Expand Up @@ -556,15 +561,23 @@ describe('lib', () => {
expect(moduleContents3).toContain(`
{
path: 'my-dir-my-lib',
loadChildren: '@proj/my-dir/my-lib#MyDirMyLibModule'
loadChildren: () =>
import('@proj/my-dir/my-lib').then(module => module.MyDirMyLibModule)
}`);
expect(moduleContents3).toContain(`
{
path: 'my-dir-my-lib2',
loadChildren: '@proj/my-dir/my-lib2#MyDirMyLib2Module'
loadChildren: () =>
import('@proj/my-dir/my-lib2').then(
module => module.MyDirMyLib2Module
)
}`);
expect(moduleContents3).toContain(`
{ path: 'my-lib3', loadChildren: '@proj/my-dir/my-lib3#MyLib3Module' }`);
{
path: 'my-lib3',
loadChildren: () =>
import('@proj/my-dir/my-lib3').then(module => module.MyLib3Module)
}`);

const tsConfigAppJson3 = JSON.parse(
stripJsonComments(
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/src/schematics/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ function addLoadChildren(options: NormalizedSchema): Rule {
sourceFile,
`{path: '${toFileName(
options.fileName
)}', loadChildren: '@${npmScope}/${options.projectDirectory}#${
options.moduleName
}'}`
)}', loadChildren: () => import('@${npmScope}/${
options.projectDirectory
}').then(module => module.${options.moduleName})}`
)
]);

Expand Down

0 comments on commit d72db4d

Please sign in to comment.