New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support passing in module to lazy-load as a callback in addition to s… #3037
Support passing in module to lazy-load as a callback in addition to s… #3037
Conversation
…tring This enables dealing with the loading of modules with a custom callback thus skipping the default NgModuleLoader. This is a must-have in order to enable lazy-loading using webpack.
Looks about right, thanks! |
Also a must for using w/ ocLazyLoad too :) |
|
@dtabuenc Whats the usage of this look like? I get:
digging in here:
I found that the import is expecting the type out whereas with:
its returning an es module. so if your import was like:
it would be returning |
I'm ok with this. v3 router also requires a lazy loaded |
I changed this function and was to get it to work using
|
Can we rename |
To use this, the callback has to return a type or a promise to a type, not an object. If using something such as webpack2 and es6 module syntax that means you have to get the "default" property. If you are using webpack1 and just a standard One way to do it in webpack 2 is just chiain the promise: loadNgModule(()=>System.import('modulePath').then( module=>module.default); An alternative (used in the angualr2 webpack starter project) is to use the string replace plugin for webpack to automatically convert the System.import: {
test: /\.ts$/,
loader: 'string-replace-loader',
query: {
search: '(System|SystemJS)(.*[\\n\\r]\\s*\\.|\\.)import\\((.+?)\\)',
replace: '$1.import($3).then(mod => (mod.__esModule && mod.default) ? mod.default : mod)',
flags: 'g'
}
} This would then allow you to do away with the extra chained then: loadNgModule(()=>System.import('modulePath')); |
The syntax is also exactly the same as v3 component router's |
@dtabuenc - that syntax is rough :S ... it would be nice if we could auto-resolve if it had a exported default ... a webpack plugin solution seems a tad excessive. |
…tring
This enables dealing with the loading of modules with a custom callback thus skipping
the default NgModuleLoader. This is a must-have in order to enable lazy-loading
using webpack.