-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Missing useBuiltIns (babel-polyfill env transform) support. #843
Comments
Just making a small note that the repo is missing the explicit |
Good idea. Want to add it? Code is here: parcel/src/transforms/babel.js Lines 242 to 255 in 0d9d14c
|
A simple add to line 252... let plugins = presetEnv.default({}, {targets, modules: false, useBuiltIns: true}).plugins; ...works, but enables useBuiltIns for all places where babel is used (or so it appears). It could be modified so that useBuiltIns is only added for the app source. I think the simple implementation would be an extra boolean flag argument to getEnvPlugins: // Line 219:
let targetEnv = await getEnvPlugins(targetEngines, true);
// Line 228
let sourceEnv = (await getEnvPlugins(sourceEngines, false)) || targetEnv;
// Line 242
async function getEnvPlugins(targets, useBuiltIns) {
// Line 252 (prettier splits this into a couple lines)
let plugins = presetEnv.default({}, {targets, modules: false, useBuiltIns: useBuiltIns ? 'entry' : false}).plugins; #878 takes this approach. |
In my case I got
maybe it's related to this issue |
@FDiskas Mostly likely not, no. That sounds like it's possibly you forgot to import babel-polyfill. |
What exactly do I need to import? It looks like |
This a 🐛 bug report
🎛 Configuration (.babelrc, package.json, cli command)
Test app repo. Note that the .babelrc file env browserlist does not include IE, nor should it include regenerator or compile generator functions.
🤔 Expected Behavior
The useBuiltIns babel-preset-env option transforms
import 'babel-polyfill';
into only the necessary individual polyfill imports. Notably, if your browserlist has support for generators, it does not import the regenerator runtime.😯 Current Behavior
Running
npx babel-cli src/index.js | less
(Linux command) shows the correct output, however, if you view/search in the compiled output from Parcel (I've been testing withnpx parcel build-dev --no-cache src/index.html
), you can see that while the babel transform is correct (generators are not compiled to use regenerator), the regenerator runtime is still included from babel-polyfill.💁 Possible Solution
I'm not familiar with Parcel internals, but one possible thought is that Parcel might be transforming
import 'babel-polyfill';
into something babel-preset-env doesn't recognize.🔦 Context
The main problem here is large unused code. Without polyfills, my example app is 4.25KB. Importing babel-polyfill (and getting all of it) brings the app to 148.23KB. If I manually use the individual polyfill imports (copied from babel-cli output), I get 31.08KB.
(I'm only picking on regenerator here because it's the one I remember the easiest, and it's easy to search for in the output (no false positives), so it's an easy test.)
🌍 Your Environment
Package versions in package.json
The text was updated successfully, but these errors were encountered: