Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I import babel-polyfill modules rather than all in?

How can I import some specific modules of babel-polyfill rather than import all ? It seems too huge size for me to import all of it and I just use few of the features of it.

What I want is like following:

import "babel-polyfill/symbol";
like image 308
Json Avatar asked Apr 01 '16 03:04

Json


1 Answers

Under the hood, the babel-polyfill uses a project called core-js (with some customisations of course). It exposes a CommonJS API, so assuming you are transpiling to CommonJS (default behaviour when using preset-es2015), you could simply use that instead:

// This pollutes the global namespace. May conflict with
// any real Symbol implementations in the future
import "core-js/es6/symbol";
// Namespace-safe Symbol import
import symbol from "core-js/es6/symbol";

It's important with this approach that you use a bundler of some sort (Browserify, Webpack, etc), because core-js is made up of a lot of smaller modules and may cause a lot of unnecessary HTTP requests.

like image 125
CodingIntrigue Avatar answered Sep 30 '22 03:09

CodingIntrigue