Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-legacy): support additionalModernPolyfills #16514

Merged
merged 1 commit into from Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/plugin-legacy/README.md
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
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
Expand Up @@ -12,6 +12,7 @@ export interface Options {
*/
polyfills?: boolean | string[]
additionalLegacyPolyfills?: string[]
additionalModernPolyfills?: string[]
/**
* default: false
*/
Expand Down