This project has a twofold purpose:
- provide easy reproducible for demonstrating and testing issues with @ngtools/webpack building lazy-loaded modules; and
- provide a bare-bones example of how to build an application with lazy-loaded modules using @ngtools/webpack, with both AOT and JIT compilation.
Note that this project uses Webpack ^2.2.0. The behaviors described herein may not apply to earlier versions of Webpack (such as the 1.0 family).
The project has the following NPM scripts for testing building the project with different configurations:
- vanilla build: JIT compilation and no DLL bundles/chunks
npm run build
- JIT compilation and DLL bundles
npm run build-with-dll
- vanilla AOT: AOT compilation and no DLL bundles/chunks
npm run aot
- AOT compilation and DLL bundles
npm run aot-with-dll
The project has the following NPM scripts for testing serving the project with different configurations (using webpack-dev-server
):
- vanilla build: JIT compilation and no DLL bundles/chunks
npm run serve
- JIT compilation and DLL bundles
npm run serve-with-dll
- vanilla AOT: AOT compilation and no DLL bundles/chunks
npm run serve-aot
- AOT compilation and DLL bundles
npm run serve-aot-with-dll
As of @ngtools/webpack 1.2.8, there are a few disparate issues reproducible by this project:
Using npm run serve
, which is the most vanilla behavior (no chunks, no DLLs), will not generate lazy loaded routes for @ngtools/webpack versions ^1.2.6. This is because the @ngtools/webpack plugin check for @angular/core/src/linker will never be triggered. You can debug this by navigating to node_modules/@ngtools/webpack/src/plugin.js
and adding the following above line 229:
console.log("ContextModuleFactory resource: " + result.resource);
To actually test this you'll need to do one of two things:
- revert @ngtools/webpack to version 1.2.4 (before the @ngtools/webpack plugin check for @angular/core/src/linker); ir
- comment out lines 229-231 of
node_modules/@ngtools/webpack/src/plugin.js
to override the@angular/core/src/linker
check.
Now, running npm run serve-with-dll
will not generate lazy loaded routes, regardless of the @ngtools/webpack version. This is because:
- the webpack compiler used by @ngtools/webpack will never parse
@angular/core/src/linker
, which just incidentally has aSystem.import
call; - the
System.import
call would then create anImportContextDependency
within the Webpack compilation; - which would then subsequently cause the calling of a
ContextModuleFactory
instance's #create method... - which would trigger the ContextModuleFactory's
after-resolve
plugin event... - which would finally trigger this part of the @ngtools/webpack plugin, which actually deals with injecting lazy-loaded modules as
ContextElementDependency
s into the Webpack compilation
This is a known issue with this project's webpack config. This project uses the DLLBundlesPlugin to keep everything in a single, simple webpack configruation and allow the DLL building to happen with the builds. Building the DLL bundles and performing the AOT compilation in the same build doesn't work quite yet, but it probably doesn't need to, since it seems DLL bundles probably aren't intended for production usage anyways.
Note that if you do want to test AOT compilation with DLL bundles for any reason, just re-running the AOT and DLL build task (e.g. npm run aot-with-dll
or npm run serve-aot-with-dll
) will work, since the DLL bundles will have been created for the second run by the first run.