shan kulkarni shan kulkarni - 1 year ago 195
AngularJS Question

Angular2 cli (Webpack) creating chunks for different modules

I am working on an Angular2 application with large no of separate modules. The module specific files(js,css,html) are fetched only when module is created dynamically (...using moduleFactory and createComponent).

So I need to bundle my app in such a way that instead of having single bundle.js, I want each module as a separate chunk so that the chunk(js) is only fetched when the module is created.

how can I achieve this in angular cli ??
will CommonsChunkPlugin be helpful?

Answer Source

You can setup your project with webpack directly without using angular-cli and use require.ensure() to include external file dynamically. Webpack will detect require.ensure() and will create a separate chunk for it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download