@volvo-cars/polyfill

Polyfills required for shared components

Usage no npm install needed!

<script type="module">
  import volvoCarsPolyfill from 'https://cdn.skypack.dev/@volvo-cars/polyfill';
</script>

README

@volvo-cars/polyfill

@volvo-cars/polyfill @volvo-cars/polyfill

This package includes the polyfills required to run @volvo-cars shared components in the browsers mandated by our browser support matrix. When available it uses polyfills from core-js@3.

Usage

npm install @volvo-cars/polyfill
# or
yarn add @volvo-cars/polyfill

Basic usage

You can import the package directly (make sure it's the first import).

import '@volvo-cars/polyfill';

Next.js

Add the plugin to your next.config.js:

const withPolyfill = require('@volvo-cars/polyfill/next-plugin');

module.exports = withPolyfill({
  // Your config
});

Webpack

Prepend to the entry in webpack.config.js

module.exports = {
  entry: ['@volvo-cars/polyfill', './src/main.js'],
};

How does it compare to @babel/polyfill?

If you don't have a lot of external dependencies, this polyfill should cover you and will be smaller than @babel/polyfill.

If you need to polyfill for other libraries or your own code, @babel/polyfill has been deprecated in favor of core-js@3.

npm install core-js@^3.0.1
import 'core-js/stable';
import '@volvo-cars/polyfill';

will not give you duplicate polyfills because this package uses core-js under the hood.

If you have a working setup with @babel/polyfill and fetch you might not need this package.

Adding new polyfills

Carefully consider whether or not the polyfill needs to be included on all sites. Large web polyfills should probably be loaded on demand.

Note that polyfills are not transpiled, so any polyfills you add need to use IE 11 compatible syntax.