Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active April 8, 2018 02:25
Show Gist options
  • Save rauschma/fc6973110700c4932d360d5eb6ad9931 to your computer and use it in GitHub Desktop.
Save rauschma/fc6973110700c4932d360d5eb6ad9931 to your computer and use it in GitHub Desktop.

Polyfillying the standard library when using babel-preset-env

Browsers

Approach for untranspiled code (meant to be transpiled by Babel and, e.g., webpack):

  • No package ever polyfills.
    • Use only functionality at stage 4 or older.
  • The entry point does import "babel-polyfill"; for which env.useBuiltins generates the imports appropriate for the current targets.
    • Benefit: the bundle only includes functionality that the target platforms don’t have. Think: custom-tailored babel-polyfill.

Node.js

For Node.js, the untranspiled code would be transpiled via target: { node: "current" }.

  • To play it safe, should every package do import "babel-polyfill"; at its entry point?
    • Note: not as problematic, because bundle size is not a factor on Node.js.
@rauschma
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment