Skip to content

Split bundles when using require with context #6164

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
Ristaaf opened this issue May 3, 2017 · 6 comments
Closed

Split bundles when using require with context #6164

Ristaaf opened this issue May 3, 2017 · 6 comments

Comments

@Ristaaf
Copy link

Ristaaf commented May 3, 2017

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Versions.

@angular/cli: 1.0.1
node: 7.8.0
os: win32 x64
@angular/animations: 4.1.0
@angular/common: 4.1.0
@angular/compiler: 4.1.0
@angular/core: 4.1.0
@angular/forms: 4.1.0
@angular/http: 4.1.0
@angular/platform-browser: 4.1.0
@angular/platform-browser-dynamic: 4.1.0
@angular/router: 4.1.0
@angular/cli: 1.0.1
@angular/compiler-cli: 4.1.0

Repro steps.

Put a number of locale files (js files named as different locales) in a folder names locales and in app.component constructor do:

let myLocaleInfo = require("./locales/"+navigator.language +".js");

ng build

You will get all locale files bundled with the main bundle (in our case we have the complete cldr-data in the locales folder, as we need to support all available locales, that means 236MB! in the main bundle, when we in practice only need to add one 600kB file (which one, we know first at runtime))

Desired functionality.

We would like each locale to become its own bundle, so that we do not get a gigant main bundle, but only load the locale actually used at runtime! This is from what I have read possible in webpack with the following syntax:

let myLocaleInfo = require("bundle-loader?lazy!./locales/"+navigator.language +".js");

However bundle-loader does not seem to exist in angular-cli

Mention any other details that might be useful.

What we are actually doing is loading locales for Globalize.js and kendo.ui, the application we are building supports 25 languages but basically all locales available in the world.

@clydin
Copy link
Member

clydin commented May 3, 2017

For information on code splitting, please refer to this guide: https://webpack.js.org/guides/code-splitting-async/

Please note that while this works, it is not considered a fully supported feature of the CLI.

@sumitarora
Copy link
Contributor

Closing as above.

@filipesilva
Copy link
Contributor

Would just like to add that we do test for this, when using System.import only: https://github.com/angular/angular-cli/blob/master/tests/e2e/tests/misc/lazy-module.ts#L30-L33

@Ristaaf
Copy link
Author

Ristaaf commented May 3, 2017

Thanks, I will try this out when I have time, although from what I can see when reading this documentation, it actually does not do what I need.

In my case it will put all the locales into the same lazy loaded bundle instead of the main bundle, this will not solve my problem where I need each locale file to be its own bundle. So I will still end up with a 250mb locales bundle instead of like 400 600k bundles which is what I need.

@Ristaaf
Copy link
Author

Ristaaf commented May 4, 2017

And for anyone reading this later on, this actually works as I need it to, I get one chunk per file!

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants