I'm working on a web project using Babel 7 with Webpack 4. I've never used Babel before and can't really understand some parts of it. Based on the documentation I'm using @babel/preset-env
because it seems the recommended way (especially for beginners). Also using Browserslist integration via my .browserslistrc
file.
Webpack does the compilation well (babel-loader
version 8.0.2
), I have no errors but I'm confused about this useBuiltIns: "entry"
option mentioned here and how polyfill
system is working in Babel.
.babelrc.js
module.exports = {
presets: [
['@babel/preset-env', {
"useBuiltIns": "entry" // do I need this?
}]
],
plugins: [
'@babel/plugin-syntax-dynamic-import'
]
};
.browserslistrc
Copied from here (thought reasonable because my project is using Bootstrap).
>= 1%
last 1 major version
not dead
Chrome >= 45
Firefox >= 38
Edge >= 12
Explorer >= 10
iOS >= 9
Safari >= 9
Android >= 4.4
Opera >= 30
So my questions are:
1) Do I need to use that useBuiltIns: "entry"
option?
2) Do I need to install @babel/polyfill
package and start my vendors.js
with require("@babel/polyfill");
?
3) What if I omit both?
If I do 1 and 2, my vendors.js
grows up to 411 KB
If I ommit both it's just 341 KB
after a production build.
I thought @babel/preset-env
handles all the rewrites and polyfills by default without any extra import/require
needed on my side...
Thanks!
-- EDIT --
Babel's team has just updated the docs of @babel/polyfill
based on some GitHub issues (including mine) complaining about unclear/misleading documentation. Now it's obvious how to use it. (...and after that my original question seems stupid :)
import "core-js/stable"; import "regenerator-runtime/runtime";
? – Hollo