Gathering detailed insights and metrics for @vitejs/plugin-legacy
Gathering detailed insights and metrics for @vitejs/plugin-legacy
Gathering detailed insights and metrics for @vitejs/plugin-legacy
Gathering detailed insights and metrics for @vitejs/plugin-legacy
@gustavotoyota/vitejs-plugin-legacy
Vite's default browser support baseline is [Native ESM](https://caniuse.com/es6-module). This plugin provides support for legacy browsers that do not support native ESM when building for production.
vite-plugin-legacy-extends
Add option `modernTargets` to `@vitejs/plugin-legacy` before official support:
@knightly/vitejs__plugin-legacy
[](https://github.com/knightlyjs/knightly) 
@qx-chitanda/vite-plugin-lib-legacy
基于官方 @vitejs/plugin-legacy@5.2.0 减配而来
Next generation frontend tooling. It's fast!
npm install @vitejs/plugin-legacy
Typescript
Module System
Min. Node Version
Node Version
NPM Version
plugin-legacy@7.0.1
Updated on Jul 17, 2025
v7.0.5
Updated on Jul 17, 2025
create-vite@7.0.3
Updated on Jul 11, 2025
create-vite@7.0.2
Updated on Jul 10, 2025
v7.0.4
Updated on Jul 10, 2025
create-vite@7.0.1
Updated on Jul 08, 2025
TypeScript (83.23%)
JavaScript (9.81%)
HTML (5.17%)
CSS (1.23%)
Vue (0.14%)
AppleScript (0.11%)
SCSS (0.1%)
Svelte (0.1%)
Less (0.05%)
Stylus (0.02%)
Shell (0.01%)
Pug (0.01%)
Sass (0.01%)
SugarSS (0.01%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
74,183 Stars
7,942 Commits
6,954 Forks
459 Watchers
42 Branches
1,128 Contributors
Updated on Jul 17, 2025
Latest Version
7.0.1
Package Id
@vitejs/plugin-legacy@7.0.1
Unpacked Size
37.57 kB
Size
11.98 kB
File Count
5
NPM Version
10.9.2
Node Version
22.17.0
Published on
Jul 17, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Vite's default browser support baseline is Native ESM, native ESM dynamic import, and import.meta
. This plugin provides support for legacy browsers that do not support those features when building for production.
By default, this plugin will:
Generate a corresponding legacy chunk for every chunk in the final bundle, transformed with @babel/preset-env and emitted as SystemJS modules (code splitting is still supported!).
Generate a polyfill chunk including SystemJS runtime, and any necessary polyfills determined by specified browser targets and actual usage in the bundle.
Inject <script nomodule>
tags into generated HTML to conditionally load the polyfills and legacy bundle only in browsers without widely-available features support.
Inject the import.meta.env.LEGACY
env variable, which will only be true
in the legacy production build, and false
in all other cases.
1// vite.config.js 2import legacy from '@vitejs/plugin-legacy' 3 4export default { 5 plugins: [ 6 legacy({ 7 targets: ['defaults', 'not IE 11'], 8 }), 9 ], 10}
Terser must be installed because plugin-legacy uses Terser for minification.
1npm add -D terser
targets
Type: string | string[] | { [key: string]: string }
Default: 'last 2 versions and not dead, > 0.3%, Firefox ESR'
If explicitly set, it's passed on to @babel/preset-env
when rendering legacy chunks.
The query is also Browserslist compatible. See Browserslist Best Practices for more details.
If it's not set, plugin-legacy will load the browserslist config sources and then fallback to the default value.
modernTargets
Type: string | string[]
Default: 'edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12'
If explicitly set, it's passed on to @babel/preset-env
when rendering modern chunks.
The query is also Browserslist compatible. See Browserslist Best Practices for more details.
If it's not set, plugin-legacy will fallback to the default value.
polyfills
Type: boolean | string[]
Default: true
By default, a polyfills chunk is generated based on the target browser ranges and actual usage in the final bundle (detected via @babel/preset-env
's useBuiltIns: 'usage'
).
Set to a list of strings to explicitly control which polyfills to include. See Polyfill Specifiers for details.
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.
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
Type: boolean | string[]
Default: false
Defaults to false
. Enabling this option will generate a separate polyfills chunk for the modern build (targeting browsers that support widely-available features).
Set to a list of strings to explicitly control which polyfills to include. See Polyfill Specifiers for details.
If modernTargets
is not set, it is not recommended to use the true
value (which uses auto-detection) because core-js@3
is very aggressive in polyfill inclusions due to all the bleeding edge features it supports. Even when targeting native ESM support, it injects 15kb of polyfills!
If you don't have hard reliance on bleeding edge runtime features, it is not that hard to avoid having to use polyfills in the modern build altogether. Alternatively, consider setting modernTargets
or using an on-demand service like https://cdnjs.cloudflare.com/polyfill/ to only inject necessary polyfills based on actual browser user-agents (most modern browsers will need nothing!).
renderLegacyChunks
Type: boolean
Default: true
Set to false
to disable legacy chunks. This is only useful if you are using modernPolyfills
, which essentially allows you to use this plugin for injecting polyfills to the modern build only:
1import legacy from '@vitejs/plugin-legacy' 2 3export default { 4 plugins: [ 5 legacy({ 6 modernPolyfills: [ 7 /* ... */ 8 ], 9 renderLegacyChunks: false, 10 }), 11 ], 12}
externalSystemJS
Type: boolean
Default: false
Defaults to false
. Enabling this option will exclude systemjs/dist/s.min.js
inside polyfills-legacy chunk.
renderModernChunks
Type: boolean
Default: true
Set to false
to only output the legacy bundles that support all target browsers.
This is also useful when running the project locally using file:
protocol, as loading modern chunks with type="module"
may trigger CORS restrictions. To avoid this issue, simply set renderModernChunks
to false
to exclusively use legacy chunks instead.
The legacy plugin offers a way to use widely-available features natively in the modern build, while falling back to the legacy build in browsers with native ESM but without those features supported (e.g. Legacy Edge). This feature works by injecting a runtime check and loading the legacy bundle with SystemJs runtime if needed. There are the following drawbacks:
SyntaxError
in browsers without those features supportThe following syntax are considered as widely-available:
import.meta
Polyfill specifier strings for polyfills
and modernPolyfills
can be either of the following:
Any core-js
3 sub import paths - e.g. es/map
will import core-js/es/map
Any individual core-js
3 modules - e.g. es.array.iterator
will import core-js/modules/es.array.iterator.js
Example
1import legacy from '@vitejs/plugin-legacy' 2 3export default { 4 plugins: [ 5 legacy({ 6 polyfills: ['es.promise.finally', 'es/map', 'es/set'], 7 modernPolyfills: ['es.promise.finally'], 8 }), 9 ], 10}
The legacy plugin requires inline scripts for Safari 10.1 nomodule
fix, SystemJS initialization, and dynamic import fallback. If you have a strict CSP policy requirement, you will need to add the corresponding hashes to your script-src
list.
The hash values (without the sha256-
prefix) can be retrieved via:
1import { cspHashes } from '@vitejs/plugin-legacy'
The current values are:
sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=
sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=
sha256-ZxAi3a7m9Mzbc+Z1LGuCCK5Xee6reDkEPRas66H9KSo=
sha256-+5XkZFazzJo8n0iOP4ti/cLCMUudTf//Mzkb7xNPXIc=
Note that these values could change between minor versions. Thus, we recommend generating the CSP header from the exported cspHashes
variable. If you copy the values manually, then you should pin the minor version using ~
.
When using the regenerator-runtime
polyfill, it will attempt to use the globalThis
object to register itself. If globalThis
is not available (it is fairly new and not widely supported, including IE 11), it attempts to perform dynamic Function(...)
call which violates the CSP. To avoid dynamic eval
in the absence of globalThis
consider adding core-js/proposals/global-this
to additionalLegacyPolyfills
to define it.
No vulnerabilities found.
Reason
30 commit(s) and 14 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
0 existing vulnerabilities detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
binaries present in source code
Details
Reason
dependency not pinned by hash detected -- score normalized to 6
Details
Reason
Found 14/27 approved changesets -- score normalized to 5
Reason
SAST tool is not run on all commits -- score normalized to 1
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More