- Overview of a workflow based on
env
: http://2ality.com/2017/07/npm-packages-via-babel.html env
has the optionuseBuiltins
that helps with polyfilling the standard library: https://github.com/babel/babel-preset-env#usebuiltins
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 whichenv.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
.
- Benefit: the bundle only includes functionality that the target platforms don’t have. Think: custom-tailored
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.
First of all, thanks for this gist!
I have two question, I'd like to clarify. Does
babel-polyfill
includeregeneratorRuntime
? And how to deal with a situation, when a library has to support browser and node.js?