Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
Babel/preset-env: confusion about setting target environment for shipping polyfills

I am learning how to use @babel/preset-env to ship browser polyfills needed for our clients. My understanding is that babel will send polyfills down if the client visiting the website is one of the target environments. And there seems to be two ways to specify the target environments: 1. browserlist 2. the targets option as in { "presets": [["@babel/preset-env", { "targets": "defaults" }]] }

But here are a few things I don't quite understand:

  1. It seems like the polyfills are all coming from core-js. And adding polyfill seems like a build time process. what I don't quite understand is how babel is actually selecting which polyfills the client needs - is babel importing all polyfills at once and only applying it at runtime if it is needed or it is only importing needed polyfills at build time? If Babel doesn't select which polyfills to apply, then how does this happen during the runtime? Can someone explain this in detail to me?
  2. What are the differences between using the targets options to set the target environments or using browserlist to set the target environments? Further more, I am confused about the default query for targets. On babel's doc it says

Because of this, preset-env's behavior is different than browserslist: it does not use the defaults query when no targets are found in your Babel or browserslist config(s). If you want to use the defaults query, you will need to explicitly pass it as a target:

So by only having { "presets": ["@babel/preset-env"] } won't give us the default query and we have to explicitly setting the target to defaults as in "presets": [["@babel/preset-env", { "targets": "defaults" }]]?

  1. This relates to my second question - if I have a project that has "@babel/preset-env" but doesn't have browserlist defined nor do I have { "targets": "defaults" } , am I still polyfilling anything or in this case we are not sending and polyfills?
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. Babel is not selecting polyfills for your client, Babel only runs at the compiling stage, and generates the output files for you, now it's up to you whether you want to serve those files for all your clients or not. Babel is not running on your server, neither on the client-side, the only time it runs is on the building stage.

  2. True, if you don't set your target, no target will be applied. It means that it babel will transform your latest code to support too many browsers that will increase your file size (or client-side performance), that's why they recommend specifying targets.

  3. Just the opposite, in that case, Babel will transform way too much, by targeting specific targets, Babel will do less work and you will only support later versions of the browsers (as you specify).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!