babel-plugin-transform-async-to-promises icon indicating copy to clipboard operation
babel-plugin-transform-async-to-promises copied to clipboard

No tree shaking with externalHelpers: true

Open pubkey opened this issue 3 years ago • 0 comments

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 avatar Dec 30 '21 05:12 pubkey