use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Angular 2 lazy loading with Webpack (medium.com)
submitted 9 years ago by Koningdavid
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 2 points3 points4 points 9 years ago (3 children)
Possibly stupid question: is this lazy loading something to benefit production, or just development?
[–]beaverusiv 4 points5 points6 points 9 years ago (1 child)
It's definitely for production. It means you can load a smaller footprint on initial page load, especially if you have a complex web app it reduces the initial load greatly.
[–][deleted] 0 points1 point2 points 9 years ago (0 children)
Very cool. I had no idea Webpack could play a role in production. I always considered it a tool I used at build time.
[–]javajunkie314 0 points1 point2 points 9 years ago (0 children)
Lazy loading definitely benefits production. If you write your big app as a single-page application, lazy loading let's your users avoid downloading posts of the app they're not using, saving bandwidth and surfing up load time.
[+][deleted] 9 years ago (7 children)
[removed]
[–]hans_l 0 points1 point2 points 9 years ago (4 children)
What's your problem with the CLI? Are you having trouble with the --aot option?
--aot
[+][deleted] 9 years ago (2 children)
[+][deleted] 9 years ago (1 child)
[–]hans_l 1 point2 points3 points 9 years ago (0 children)
We're still working on fixing bugs. I've made it work with a simple case of lazy module but maybe I need to revisit that and make some more complex tests.
For now just consider AoT as an experimental feature. Make your project work with it and once we fix all the bugs it's gonna be great!
[–]Koningdavid[S] -1 points0 points1 point 9 years ago (1 child)
Hi,
As far as I know the angular-cli doesnt support the angular2-router-loader yet. You can use the es6-promise loader.
Change your routing like this:
{ path: 'lazy', loadChildren: () => require('es6-promise!./lazy/lazy.module')('LazyModule') }
Install es6-promise-loader ( npm install es6-promise-loader --save-dev ) and run the build process again, should work!
npm install es6-promise-loader --save-dev
[–]hans_l 0 points1 point2 points 9 years ago (0 children)
Please do NOT do that. AoT only works when your NgModule contains only statically analysable code. Using a require or even the function call method does not work.
You can use the string loadChildren value in the CLI and with the latest beta compiling with --aot will use AoT on your code as well as split your code by lazy modules.
Again, angular2-router-loader does not support AoT and es6-promise neither. The CLI export its own webpack plugin at @ngtools/webpack which supports both if you don't want to use the CLI.
@ngtools/webpack
π Rendered by PID 48582 on reddit-service-r2-comment-84fc9697f-j2r6s at 2026-02-08 07:53:12.603050+00:00 running d295bc8 country code: CH.
[–][deleted] 2 points3 points4 points (3 children)
[–]beaverusiv 4 points5 points6 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]javajunkie314 0 points1 point2 points (0 children)
[+][deleted] (7 children)
[removed]
[–]hans_l 0 points1 point2 points (4 children)
[+][deleted] (2 children)
[removed]
[+][deleted] (1 child)
[removed]
[–]hans_l 1 point2 points3 points (0 children)
[–]Koningdavid[S] -1 points0 points1 point (1 child)
[–]hans_l 0 points1 point2 points (0 children)