Babel config should follow browsers specification
See original GitHub issueUsing babel-preset-es2015
is now considered bad practice, and babel-preset-env
is preferred.
This is because the env
plugin allows for specifying a list of target browsers, which enables babel to automatically determine which plugins and polyfills to use, resulting in less code. https://github.com/babel/babel-preset-env
It will also enable code size to go down as we remove supported browsers in the future (looking at you, IE 11).
Tasks:
- Replace
babel-preset-es2015
bybabel-preset-env
inpackage.json
- Set up an
env
configuration inpackage.json
matching our supported browsers (validate string at http://browserl.ist/) - Ensure the output includes no polyfills, adjusting options if needed (see
useBuiltIns
andexclude
options) - Ensure output remains sane and works across all supported browsers
- (Optional) Measure generated JS size delta and brag about it on this issue 😃 Note that this may actually be small because of IE11 😦
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Configure Babel
Create a file called babel.config.json with the following content at the root of your project (where the package.json is). { "presets": [...], "plugins":...
Read more >Options - Babel.js
This is useful for projects that use a browserslist config for files that won't be compiled with Babel. If a string is specified,...
Read more >babel/preset-env
By default @babel/preset-env will use browserslist config sources unless either the targets or ignoreBrowserslistConfig options are set.
Read more >Config Files - Babel.js
New in Babel 7.x, Babel has a concept of a "root" directory, which defaults to the current working directory. For project-wide configuration, Babel...
Read more >Presets - Babel.js
Babel presets can act as sharable set of Babel plugins and/or config ... Stage 3 - Candidate: complete spec and initial browser implementations....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@traviskaufman It might not even be necessary, as afaik you can run it through Babel with
babel-preset-babili
.I’ve done some experimentation and these are my findings.
Before:
After:
So that’s a whopping difference of 0 bytes.
As an experiment I removed IE 11 and got this:
A difference of 612 bytes, but with a big caveat. It will fail on creating the
.min.js
file, aswebpack
usesuglifyjs
internally to minify the code and it doesn’t yet support es2016 (or later) code.So switching from
babel-preset-es2015
tobabel-preset-env
isn’t viable untilwebpack
/uglifyjs
support es2016 (and newer) imho.