angular-cli: Using @ngtools/webpack with ContextReplacementPlugin plugin does not create lazy routes chunks
OS?
Ubuntu 16.04
Versions.
@ngtools/webpack - 1.2.7
Repro steps.
- create simple webpack config with
@ngtools/webpackusage and app with lazy routes (e.g. this example repo https://github.com/daniele-zurico/webpack-aot) - add to webpack config plugins
ContextReplacementPluginusage like so
plugins: [
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
__dirname
),
- run build
npm run build - no chunks for lazy routes in
distfolder - comment out
ContextReplacementPluginin plugins, build, chunks created
Mention any other details that might be useful.
this check never passes with ContextReplacementPlugin usage
https://github.com/angular/angular-cli/blob/29b134d7018c7d4e2eed74715b30b28e56fdcd49/packages/%40ngtools/webpack/src/plugin.ts#L247
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 10
- Comments: 21 (2 by maintainers)
I have the same problem with version 1.3.1. Any news on this?
Perhaps this should be a separate issue, will leave here for now. The plugin (
"@ngtools/webpack": "^1.2.11") also silently fails to generate lazyload routes when using the webpackhtml-loader. Also facing same issues with ContextReplacement & CommonsChunk plugin.Added repo where both issues can be reproduced https://github.com/artaommahe/webpack-aot
App contains 3 modules
AppModulethat importsSharedModuleFeatureModulethat also importsSharedModuleSharedModulewith commonly used componentFor proper work there should be 3 bundles in
./distfolder onnpm run buildcommandvendor.jswith all common libs (angular, corejs)main.jswithAppModuleandSharedModule0.jschunk with onlyFeatureModuleContextReplacementPlugin issue
Uncomment this https://github.com/artaommahe/webpack-aot/blob/master/webpack.config.js#L21 and after
npm run buildthere will be no chunks generated indistfolderCommonsChunkPlugin issue
Run build as it is and see that
0.jschunk also containsSharedModule. Change plugin options like soand
0.jschunk propely contains onlyFeatureModule, butmain.jsholds all app libs that should be invendor.js@sumitarora all in all, I must say I’m not sure the two issues are really duplicate. Others here are reporting that they cannot build when commenting out that replacement plugin, while I can. Also, we don’t even know if they share the same steps (e.g. does build fail? Does opening page fail? Does browsing to lazy module fail?) and the same stacktrace.
Just my 2c
watching…