3

Is there a way to "tree shake" babel-polyfill, such that only the features I use are polyfilled?

That is, if I never use String.padStart in my code, it's polyfill should not be included.

Birjolaxew
  • 807
  • 9
  • 25
  • I would also like to know this. I'm even ok with a good CLI i can run on occasion to figure out all the requires like `require('core-js/fn/array/some');` i would need to add – Arron Aug 01 '17 at 04:46

1 Answers1

0

I was able to do it using CoreJS 3 (beta) core-js@3.0.0-beta.3. Babel polyfill also uses core-js so I think you can use below method:

npm install --save core-js@3.0.0-beta.3

Then in your JS code you can import your desired polyfills as below (ES syntax):

import "core-js/features/array/includes";
import "core-js/features/string/starts-with";

So far it's working great for me!

Sachin Singh
  • 898
  • 1
  • 8
  • 17