Hi I\'m trying to use angular-cli with webpack (+productivity) to build my angular2 app but I\'m having issues when trying to lazy load modules which were working with versi
There's a loader for this (angular2-router-loader). However you can't use it with the CLI without hacking the config. Luckily, es6-promise-loader
does work with the CLI out-of-the-box.
This is what worked out for me:
First we'll need the es6-promise-loader:
npm i --save-dev es6-promise-loader
Then define your route like this:
{path:"lazy", loadChildren: () => require('es6-promise!./path/to/module')('ClassName')}
the es6-promise-loader
replaces the above with this:
loadChildren: () => new Promise(function (resolve) {
require.ensure([], function (require) {
resolve(require('./path/to/module')['ClassName']));
});
});
which is the proper way to load a module with webpack, but cumbersome to put into every route.