shan kulkarni
shan kulkarni

Reputation: 855

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?

Upvotes: 1

Views: 687

Answers (1)

Lav Vishwakarma
Lav Vishwakarma

Reputation: 1426

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.

Upvotes: 1

Related Questions