Skip to content

Commit 2322657

Browse files
authored
feat(plugin-legacy): support additionalModernPolyfills (#16514)
1 parent f222406 commit 2322657

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

packages/plugin-legacy/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ npm add -D terser
7474

7575
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.
7676

77-
Note: if additional polyfills are needed for both the modern and legacy chunks, they can simply be imported in the application source code.
77+
### `additionalModernPolyfills`
78+
79+
- **Type:** `string[]`
80+
81+
Add custom imports to the modern 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.
7882

7983
### `modernPolyfills`
8084

packages/plugin-legacy/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
166166
)
167167
})
168168
}
169+
if (Array.isArray(options.additionalModernPolyfills)) {
170+
options.additionalModernPolyfills.forEach((i) => {
171+
modernPolyfills.add(i)
172+
})
173+
}
169174
if (Array.isArray(options.polyfills)) {
170175
options.polyfills.forEach((i) => {
171176
if (i.startsWith(`regenerator`)) {

packages/plugin-legacy/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface Options {
1212
*/
1313
polyfills?: boolean | string[]
1414
additionalLegacyPolyfills?: string[]
15+
additionalModernPolyfills?: string[]
1516
/**
1617
* default: false
1718
*/

0 commit comments

Comments
 (0)