Performant generation of coreJS polyfill bundles optimized for target browsers at runtime
A service like this one integrated with a good polyfills source like core-js, which only loads the needed polyfills by statically analyzing the source like Babel's useBuiltIns: usage option does could cause a revolution in the way we think about polyfills.
This module is the core of what is needed to fulfill the next generation approach to loading polyfills.
npm install --save @vrbo/nimbuild-corejs
Import module and prime cache
const {primeCache} = require('@vrbo/nimbuild-corejs');
primeCache(); // async, takes up to 20 seconds
When processing an HTTP request, generate coreJS polyfill string with this usage:
const {getPolyfillString} = require('@vrbo/nimbuild-corejs');
const coreJSData = await getPolyfillString({
include: ['es.*'],
exclude: [],
logger: {log: console.log},
minify: true,
uaString: http.headers['user-agent']
});
return coreJSData.script; // polyfill string
npm start
This projects supports auto-formatting of source code! Simply find your favorite IDE from the list in the following list: https://prettier.io/docs/en/editors.html
For VSCode support, perform the following steps:
- Launch VS Code Quick Open (Ctrl+P)
- Paste the following command, and press enter:
ext install esbenp.prettier-vscode