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

Improve treeshaking of compiled/published multi-component files #29

Open
wessberg opened this issue Sep 27, 2018 · 0 comments
Open

Improve treeshaking of compiled/published multi-component files #29

wessberg opened this issue Sep 27, 2018 · 0 comments

Comments

@wessberg
Copy link
Member

Problem

If we have a file like this:

// module-a

class MyComponent1 { ... }
___registerElement("my-component-1", MyComponent1);
class MyComponent2 { ... }
___registerElement("my-component-2", MyComponent2);

...And we make an import like this:

// module-b
import {MyComponent1} from "./module-a";

...MyComponent2 won't be treeshaken with for example Rollup, since the calls to "___registerElement" may have side effects.

This is unfortunate since this may lead to scenarios with files exporting many components none of which will be treeshaken.

Solution

[WIP]

Rather than declare the static helper calls inside the top-level scope of files declaring components, the helper calls should be embedded within the class-scope of the components.

One way to do so is to place all of them inside the already-defined static bootstrap method of components.

One last thing that is then needed is to avoid calling ___bootstrap from the top-level scope, but instead have the component itself do that somehow.

@wessberg wessberg changed the title Improve treeshaking of multi-component files Improve treeshaking of compiled/published multi-component files Sep 27, 2018
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

1 participant