@vrbo/nimbuild-corejs

Performant generation of coreJS polyfill bundles optimized for target browsers at runtime

Usage no npm install needed!

<script type="module">
  import vrboNimbuildCorejs from 'https://cdn.skypack.dev/@vrbo/nimbuild-corejs';
</script>

README

@vrbo/nimbuild-corejs

NPM Version Build Status

Performant generation of coreJS polyfill bundles optimized for target browsers at runtime

Why

Read: https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md#better-optimization-of-polyfill-loading

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.

Installation

npm install --save @vrbo/nimbuild-corejs

Usage

Import module, configure, and prime cache

const {
    addSupported,
    clearSupported,
    initializeSupported,
    primeCache,
    serializeCache,
    deserializeCache
} = require('@vrbo/nimbuild-corejs');

// Initialize supported corejs modules
initializeSupported(); // use `nimbuild-corejs` defaults
// or customize supported corejs modules
initializeSupported({
    'my-default': {
        include: [
            /* custom core-js modules */
        ],
        exclude: [
            /* custom core-js modules */
        ]
    }
});

// Runs webpacknimbuild.run() on every browser platform
await primeCache();

// Get serialized cache
const serializedData = serializeCache();

// Set cache from serialized data
deserializeCache(serializedData);

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

Development

Starting development harness

npm start

Prettier

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