Skip to content

Commit ca25896

Browse files
committed
feat(plugin-legacy): support additionalLegacyPolyfills
close #1475
1 parent 0bb6ddb commit ca25896

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

packages/plugin-legacy/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export default {
4949

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

52+
### `additionalLegacyPolyfills`
53+
54+
- **Type:** `string[]`
55+
56+
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.
57+
58+
Note: if additional plyfills are needed for both the modern and legacy chunks, they can simply be imported in the application source code.
59+
5260
### `ignoreBrowserslistConfig`
5361

5462
- **Type:** `boolean`

packages/plugin-legacy/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface Options {
1313
* default: true
1414
*/
1515
polyfills?: boolean | string[]
16+
additionalLegacyPolyfills?: string[]
1617
/**
1718
* default: false
1819
*/

packages/plugin-legacy/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ function viteLegacyPlugin(options = {}) {
5656
}
5757
})
5858
}
59+
if (Array.isArray(options.additionalLegacyPolyfills)) {
60+
options.additionalLegacyPolyfills.forEach((i) => {
61+
legacyPolyfills.add(i)
62+
})
63+
}
5964

6065
/**
6166
* @type {import('vite').Plugin}

0 commit comments

Comments
 (0)