Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type LoaderCodeGen = Function & (
| ( (file: string, module: string, loaderOptions: RouterLoaderOptions, resourceOptions: RouteResourceOptions) => string )
)

const LOAD_CHILDREN_RE = /loadChildren[\s]*:[\s]*['|"].+?['|"]/;
const LOAD_CHILDREN_RE = /loadChildren[\s]*:[\s]*['|"].*#{1}.*['|"]/;

export class Loader {
public query: RouterLoaderOptions;
Expand Down
6 changes: 4 additions & 2 deletions src/builtin_codegens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ systemCodeGen['deprecated'] = () => {
systemCodeGen['deprecated'] = () => {};
};

export const importCodeGen: LoaderCodeGen = (file: string, module: string, opts: RouterLoaderOptions) => {
export const importCodeGen: LoaderCodeGen = (file: string, module: string, opts: RouterLoaderOptions, resourceOptions: RouteResourceOptions) => {
const webpackChunkName = resourceOptions.chunkName ? ` /* webpackChunkName: "${resourceOptions.chunkName}" */` : '';

const result = [
`function importCodeGen() { return import_('${file}')`,
`function importCodeGen() { return import_('${file}'${webpackChunkName})`,
` .then( function(module) { return module['${module}']; } ); }`
];

Expand Down
11 changes: 11 additions & 0 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,17 @@ describe('Loader', () => {
});
});

it('should output async-import codegen with chunk name', () => {
const loader = factory
.setOption('loader', 'async-import')
.toLoader();

return loader.replace(genCode('app/module-container/child-module#ChildModule?chunkName=foo'))
.then(mapToZero)
.then( (result: ReplaceResult) => {
expect(result.replacement).to.eql(`function() { return import('${cwdJoin('src/app/module-container/child-module/index')}' /* webpackChunkName: "foo" */) .then( function(module) { return module['ChildModule']; } ); }`);
});
});

it('should output a custom codegen', () => {
const loader = factory.toLoader();
Expand Down