ember-cli-babel-polyfills

2.0.1 • Public • Published

ember-cli-babel-polyfills

This addon automatically includes a split build of the Babel polyfills in your Ember application! This includes three files that are added programmatically to your index.html:

  1. polyfill-shared.js
  2. polyfill-evergreen.js
  3. polyfill-legacy.js

The shared file contains the common code between both polyfills, while the others contain whatever is unique to them. Importantly, the polyfill-legacy file (which is usually the largest!) is marked with the nomodule attribute. This attribute prevents the file from loading in all modern browsers, so it only impacts your legacy users. For more details, see the MDN documentation.

Why would I want an evergreen polyfill?

It turns out that browsers almost always have inconsistencies, even when they aren't updating only once-per-Windows-release! For instance, Microsoft Edge does not yet implement the DOM iterable API as of 01/24/19 (try checking for document.forms[Symbol.iterator] in the developer console).

These polyfills are built dynamically using Babel's presetEnv, so they'll stay up to date even as the browsers themselves are changing. Best of all, you only ship the things you care about to modern browsers!

Installation

ember install ember-cli-babel-polyfills

Usage

Installing the addon will automatically include the polyfills without any additional configuration. You can opt to configure the addon with the following options:

interface EmberCliBabelPolyfillsConfig {
  legacyTargets?: string[];
  evergreenTargets?: string[];
  includeScriptTags?: boolean;
}

evergreenTargets

The evergreen browsers you want to support, provided in browserslist format. Defaults to the following:

const evergreenTargets = [
  'last 2 Chrome versions',
  'last 2 Firefox versions',
  'last 2 Safari versions',
  'last 2 Edge versions',
  'last 2 ChromeAndroid versions',
  'last 2 iOS versions',
]

Example Usage:

// ember-cli-build.js
 
let app = new EmberApp(defaults, {
  'ember-cli-babel-polyfills': {
    evergreenTargets: [
      'last 1 Chrome versions',
      'last 1 Firefox versions',
      'last 1 Safari versions',
    ],
  },
});

legacyTargets

The legacy browsers you want to support, provided in browserslist format. Defaults to your app's targets.

Example Usage:

// ember-cli-build.js
 
let app = new EmberApp(defaults, {
  'ember-cli-babel-polyfills': {
    legacyTargets: [
      "last 1 version",
      "> 1%",
      "maintained node versions",
      "not dead",
    ],
  },
});

includeScriptTags

Whether or not the addon should inject script tags into your content for body. Defaults to true.

Example Usage:

// ember-cli-build.js
 
let app = new EmberApp(defaults, {
  'ember-cli-babel-polyfills': {
    includeScriptTags: false,
  },
});

License

This project is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i ember-cli-babel-polyfills

Weekly Downloads

3,724

Version

2.0.1

License

MIT

Unpacked Size

377 kB

Total Files

7

Last publish

Collaborators

  • pzuraq