Skip to content

Commit

Permalink
feat(plugin-legacy): support additionalLegacyPolyfills
Browse files Browse the repository at this point in the history
close #1475
  • Loading branch information
yyx990803 committed Jan 11, 2021
1 parent 0bb6ddb commit ca25896
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/plugin-legacy/README.md
Expand Up @@ -49,6 +49,14 @@ export default {

Set to `false` to avoid generating polyfills and handle it yourself (will still generate legacy chunks with syntax transformations).

### `additionalLegacyPolyfills`

- **Type:** `string[]`

Add custom imports to the legacy polyfills chunk. Since the usage-based polyfill detection only covers ES language features, it may be necessary to manually specify additional DOM API polyfills using this option.

Note: if additional plyfills are needed for both the modern and legacy chunks, they can simply be imported in the application source code.

### `ignoreBrowserslistConfig`

- **Type:** `boolean`
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-legacy/index.d.ts
Expand Up @@ -13,6 +13,7 @@ export interface Options {
* default: true
*/
polyfills?: boolean | string[]
additionalLegacyPolyfills?: string[]
/**
* default: false
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-legacy/index.js
Expand Up @@ -56,6 +56,11 @@ function viteLegacyPlugin(options = {}) {
}
})
}
if (Array.isArray(options.additionalLegacyPolyfills)) {
options.additionalLegacyPolyfills.forEach((i) => {
legacyPolyfills.add(i)
})
}

/**
* @type {import('vite').Plugin}
Expand Down

0 comments on commit ca25896

Please sign in to comment.