# @open-wc/rollup-plugin-polyfills-loader

> Plugin for generating an html file with rollup

Latest version **1.1.8** (published 2020-10-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @open-wc/rollup-plugin-polyfills-loader
pnpm add @open-wc/rollup-plugin-polyfills-loader
yarn add @open-wc/rollup-plugin-polyfills-loader
bun add @open-wc/rollup-plugin-polyfills-loader
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.8 |
| Published | 2020-10-28 |
| First published | 2020-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 23.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2400 |
| Author | open-wc |
| Maintainers | modern-web, larsdenbakker, d4kmor |
| Keywords | rollup-plugin, minify, html, polyfill |

## Links

- npm: https://www.npmjs.com/package/@open-wc/rollup-plugin-polyfills-loader
- Repository: https://github.com/open-wc/open-wc
- Homepage: https://github.com/open-wc/open-wc/packages/rollup-plugin-polyfills-loader
- Issues: https://github.com/open-wc/open-wc/issues
- npm.io page: https://npm.io/package/@open-wc/rollup-plugin-polyfills-loader

## Dependencies (2)

- [polyfills-loader](https://npm.io/package/polyfills-loader.md) ^1.7.5
- [@open-wc/rollup-plugin-html](https://npm.io/package/@open-wc/rollup-plugin-html.md) ^1.2.5

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.1.8 (latest) — 2020-10-28
- 1.1.7 — 2020-10-11
- 1.1.6 — 2020-10-03
- 1.1.5 — 2020-09-25
- 1.1.4 — 2020-08-27
- 1.1.3 — 2020-08-07
- 1.1.2 — 2020-08-05
- 1.1.1 — 2020-08-04
- 1.1.0 — 2020-08-03
- 1.0.7 — 2020-05-27
- 1.0.6 — 2020-05-17
- 1.0.5 — 2020-05-13
- 1.0.4 — 2020-05-05
- 1.0.3 — 2020-04-21
- 1.0.2 — 2020-04-20
- … 14 more at https://npm.io/package/@open-wc/rollup-plugin-polyfills-loader/versions

## README

---
permalink: 'building/rollup-plugin-polyfills-loader.html'
title: Rollup Plugin Polyfills Loader
section: guides
tags:
  - guides
---

# Rollup Plugin Polyfills Loader

Inject [Polyfills Loader](https://github.com/open-wc/open-wc/tree/master/packages/polyfills-loader) into a HTML file generated by [@open-wc/rollup-plugin-html](https://github.com/open-wc/open-wc/tree/master/packages/rollup-plugin-html).

## Examples

### Basic rollup build

```js
import html from '@open-wc/rollup-plugin-html';
import polyfillsLoader from '@open-wc/rollup-plugin-polyfills-loader';

export default {
  output: {
    dir: 'dist',
  },
  plugins: [
    html({
      inputPath: 'index.html',
      inject: false,
    }),
    polyfillsLoader({
      polyfills: {
        coreJs: true,
        fetch: true,
        webcomponents: true,
      },
    }),
  ],
};
```

### Multiple rollup build outputs

```js
import html from '@open-wc/rollup-plugin-html';
import polyfillsLoader from '@open-wc/rollup-plugin-polyfills-loader';

const htmlPlugin = html({
  inputPath: 'demo/single-build/index.html',
  inject: false,
});

export default {
  output: [
    {
      format: 'system',
      dir: './demo/dist/legacy',
      plugins: [htmlPlugin.addOutput('legacy')],
    },
    {
      format: 'es',
      dir: './demo/dist',
      plugins: [htmlPlugin.addOutput('modern')],
    },
  ],
  plugins: [
    htmlPlugin,
    polyfillsLoader({
      modernOutput: 'modern',
      legacyOutput: { name: 'legacy', test: "!('noModule' in HTMLScriptElement.prototype)" },
      polyfills: {
        coreJs: true,
        fetch: true,
        webcomponents: true,
      },
    }),
  ],
};
```

### Customized file type

```js
import html from '@open-wc/rollup-plugin-html';
import polyfillsLoader from '@open-wc/rollup-plugin-polyfills-loader';

const htmlPlugin = html({
  inputPath: 'demo/single-build/index.html',
  inject: false,
});

export default {
  output: [
    {
      format: 'es',
      dir: './demo/dist',
      plugins: [htmlPlugin.addOutput('modern')],
    },
    {
      format: 'es',
      dir: './demo/dist/legacy',
      plugins: [htmlPlugin.addOutput('legacy')],
    },
  ],
  plugins: [
    htmlPlugin,
    polyfillsLoader({
      modernOutput: { name: 'modern', type: 'module' },
      legacyOutput: {
        name: 'legacy',
        type: 'system',
        test: "!('noModule' in HTMLScriptElement.prototype)",
      },
      polyfills: {
        coreJs: true,
        fetch: true,
        webcomponents: true,
      },
    }),
  ],
};
```

### Multi page build

```js
import html from '@open-wc/rollup-plugin-html';
import polyfillsLoader from '@open-wc/rollup-plugin-polyfills-loader';

export default {
  output: {
    dir: './demo/dist',
  },
  plugins: [
    html({
      inputPath: './demo/multi-page/index.html',
    }),
    polyfillsLoader({
      htmlFileName: 'index.html',
      polyfills: { coreJs: true, fetch: true },
    }),

    html({
      inputPath: './demo/multi-page/pages/page-a.html',
      name: 'pages/page-a.html',
    }),
    polyfillsLoader({
      htmlFileName: 'pages/page-a.html',
      polyfills: { coreJs: true, fetch: true },
    }),

    html({
      inputPath: './demo/multi-page/pages/page-b.html',
      name: 'pages/page-b.html',
    }),
    polyfillsLoader({
      htmlFileName: 'pages/page-b.html',
      polyfills: { coreJs: true, fetch: true },
    }),

    html({
      inputPath: './demo/multi-page/pages/page-c.html',
      name: 'pages/page-c.html',
    }),
    polyfillsLoader({
      htmlFileName: 'pages/page-c.html',
      polyfills: { coreJs: true, fetch: true },
    }),
  ],
};
```

You can make this shorter with a helper function:

```js
import html from '@open-wc/rollup-plugin-html';
import polyfillsLoader from '@open-wc/rollup-plugin-polyfills-loader';

function createPage(inputPath, name) {
  return [
    html({ inputPath, name }),
    polyfillsLoader({
      htmlFileName: name,
      polyfills: { coreJs: true, fetch: true },
    }),
  ];
}

export default {
  output: {
    dir: './demo/dist',
  },
  plugins: [
    ...createPage('./demo/multi-page/index.html', 'index.html'),
    ...createPage('./demo/multi-page/pages/page-a.html', 'pages/page-a.html'),
    ...createPage('./demo/multi-page/pages/page-b.html', 'pages/page-b.html'),
    ...createPage('./demo/multi-page/pages/page-c.html', 'pages/page-c.html'),
  ],
};
```

## Types

```ts
import { PolyfillsConfig, FileType } from 'polyfills-loader';

export interface OutputConfig {
  name: string;
  type?: FileType;
}

export interface LegacyOutputConfig extends OutputConfig {
  test: string;
}

export interface PluginOptions {
  htmlFileName?: string;
  modernOutput?: OutputConfig;
  legacyOutput?: LegacyOutputConfig | LegacyOutputConfig[];
  polyfills?: PolyfillsConfig;
}
```

---
_Source: https://npm.io/package/@open-wc/rollup-plugin-polyfills-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
