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

No tree shaking with externalHelpers: true #78

Open
pubkey opened this issue Dec 30, 2021 · 0 comments
Open

No tree shaking with externalHelpers: true #78

pubkey opened this issue Dec 30, 2021 · 0 comments

Comments

@pubkey
Copy link

pubkey commented Dec 30, 2021

When using externalHelpers: true, all helpers are imported from the helpers.js file.
This is not optimal because the helpers.js file is not a module and therefore will prevent tree shaking when bundling.
Instead we should provide a package.json that handles the export of the helpers. There we can set sideEffects: false and also use the .mjs file if possible.

I tried that out by adding the following package.json in node_modules/babel-plugin-transform-async-to-promises/helpers/package.json

{
    "name": "babel-plugin-transform-async-to-promises-helpers",
    "main": "../a-helpers.js",
    "jsnext:main": "../a-helpers.mjs",
    "module": "../a-helpers.mjs",
    "sideEffects": false
}  

Notice that I prefixed the helpers files with a- to ensure that the bundler picks the package.json instead of the plain file when importing like import { _await } from "babel-plugin-transform-async-to-promises/helpers";.

This worked for me and decreased the overall bundle size.

@pubkey pubkey changed the title Not tree shaking with externalHelpers: true No tree shaking with externalHelpers: true Dec 30, 2021
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