Skip to content
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

Multiple instances of the same module in different bundles #1331

Closed
lastmjs opened this issue Mar 11, 2017 · 2 comments
Closed

Multiple instances of the same module in different bundles #1331

lastmjs opened this issue Mar 11, 2017 · 2 comments

Comments

@lastmjs
Copy link

lastmjs commented Mar 11, 2017

This is mostly a question, but I am hoping for a solution. Without any bundling, imagine one module that is imported into multiple JavaScript files in a single page application in the browser. Following the true es6 modules spec, I believe the loader would load the module only once, creating one single instance of that module.

Now let's add bundling. Imagine there are multiple bundles that import that one module, and those bundles are then included into that single page application in the browser. Will the browser have one instance of the module, or multiple instances?

If the answer is multiple instances, that is not ideal, since it does not follow the es6 modules spec as far as I know. I have also seen problems with this when using other bundlers, because I had a stateful module that was imported into multiple bundles, and at runtime changes to the state of the module from one bundle would not be reflected in the other bundles as I expected, since the module was not a singleton, but was multiple instances.

@marvinhagemeister
Copy link

Currently rollup does not support code splitting. Your best option is to create the different bundles by hand and exclude duplicates.

@lastmjs
Copy link
Author

lastmjs commented Apr 18, 2017

If anyone is curious, see here for more info on the code splitting conversation: #372

@lastmjs lastmjs closed this as completed Apr 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants