Skip to content

Commit

Permalink
feat(plugin-legacy): support additionalModernPolyfills (#16514)
Browse files Browse the repository at this point in the history
  • Loading branch information
iammminzzy authored Apr 30, 2024
1 parent f222406 commit 2322657
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/plugin-legacy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ npm add -D terser

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 polyfills are needed for both the modern and legacy chunks, they can simply be imported in the application source code.
### `additionalModernPolyfills`

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

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.

### `modernPolyfills`

Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
)
})
}
if (Array.isArray(options.additionalModernPolyfills)) {
options.additionalModernPolyfills.forEach((i) => {
modernPolyfills.add(i)
})
}
if (Array.isArray(options.polyfills)) {
options.polyfills.forEach((i) => {
if (i.startsWith(`regenerator`)) {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-legacy/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface Options {
*/
polyfills?: boolean | string[]
additionalLegacyPolyfills?: string[]
additionalModernPolyfills?: string[]
/**
* default: false
*/
Expand Down

0 comments on commit 2322657

Please sign in to comment.