Skip to content

Lazy Loading with Webpack? #191

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

Closed
dguisinger opened this issue Apr 18, 2017 · 6 comments · Fixed by #197
Closed

Lazy Loading with Webpack? #191

dguisinger opened this issue Apr 18, 2017 · 6 comments · Fixed by #197
Labels

Comments

@dguisinger
Copy link

Is there a way to setup lazy loading with webpack?

When I use lazy loading in my routes, it seems inconsistent, sometimes it works, sometimes it tells me it can't find the module. But more than that, obviously we are packing the whole project into a single JS file which is the opposite of lazy loading.

Is there an easy way to add a module that lazy loads to the example that has its JS loaded on the fly vs in the main client js file?

@MarkPieszak
Copy link
Member

You should be able to just do { path: 'whatever', loadChildren: 'app/whatever/whatever.module#WhateverModule' }

Is that not working?
We use ngtools here, so it's just like the angular-cli

@dguisinger
Copy link
Author

It wasn't working consistently. I'm not sure where the problem would be originating from.
I have a App Routing module located in app/modules/routingmodule.... i couldn't get to work consistently... which is weird. Sometimes I would run the project and routing links would work fine, other times I'd run it and it would tell me it couldn't find the modules... the fact that it wasn't being consistent was confusing.

Does it only work if I define the routes in the main app module? The Angular website recommends having a routes specific module.

MarkPieszak added a commit that referenced this issue Apr 19, 2017
closes #191

updates #165 (still needs to have speed improved)
MarkPieszak added a commit that referenced this issue Apr 19, 2017
closes #191

updates #165 (still needs to have speed improved)
@MarkPieszak
Copy link
Member

Added lazy loading demo into application, take a look at PR #197 to see what you were missing!
Hope that helps 👍

@dguisinger
Copy link
Author

dguisinger commented Apr 19, 2017 via email

@MarkPieszak
Copy link
Member

Yeah I just kept everything in the app.module mainly to keep things easier for people, so they don't have to import things twice, once in the declarations, and once again in a different routing file.

Glad it's working at least now, I can't imagine why having a routing module would affect anything, bizarre!

@yoosif0
Copy link

yoosif0 commented Jul 17, 2017

Yes that is so strange
Update:
In the demo I refactored routes to its own module and it is still working, but it is not working in my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants