P
P
PaulZi2018-09-13 23:34:56
JavaScript
PaulZi, 2018-09-13 23:34:56

Is it possible to make a js library that would include polyfills depending on browserslist?

Suppose I want to write a JS library that implements some functionality. For some browsers (ie11), you need to include several polyfills (CustomEvent, Element.closest and several custom implementations) to work.
Question. Is it possible to somehow organize the assembly of the js-bundle, depending on the current supported browsers, registered somewhere in browserslist.rc, so that polyfills that are not needed do not get into the bundle?
I know that babel can do this with core-js , but how do I set it up with my polyfills?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2018-09-14
@bingo347

Write it in the README, something like:

## Requirements

- CustomEvent
- Element.closest

You can import polyfills:

```javascript
import 'your-library-name/polyfills';
```

Well, put the polyfills.js file in the root of the package.
Who needs old browsers - will connect himself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question