Registry / devops / vite-plugin-legacy-swc

vite-plugin-legacy-swc

JSON →
library2.0.1jsnpmunverified

vite-plugin-legacy-swc is a Vite plugin designed to provide robust legacy browser support for production builds by leveraging SWC for efficient JavaScript transpilation. As of its current stable version, 2.0.1, the plugin offers a significantly faster alternative to `@vitejs/plugin-legacy`, with benchmark results indicating a 58% reduction in CPU time and a 4% decrease in JS asset size. It operates by generating corresponding legacy chunks for each bundle chunk, transforming them into SystemJS modules using `@swc/core`, and automatically injecting necessary polyfills and the SystemJS runtime based on specified browser targets and actual code usage. The plugin intelligently injects `<script nomodule>` tags into the generated HTML, ensuring that legacy bundles and polyfills are conditionally loaded only in browsers that require them. The project has a consistent release cadence, with multiple updates throughout 2024 and 2025 addressing bug fixes and introducing new features.

npm install vite-plugin-legacy-swc
INSTALL
IMPORT
SIG · VITE-PLUGIN-LEGACY
V
vite-plugin-legacy-swc
devopsjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

legacy
import legacy from 'vite-plugin-legacy-swc'
const legacy = require('vite-plugin-legacy-swc')
The package became ESM-only in v2.0.0; CommonJS `require` is no longer supported.

This quickstart demonstrates how to configure vite-plugin-legacy-swc in a Vite project to enable legacy browser support for production builds, specifying targets for both modern and legacy bundles.

import { defineConfig } from 'vite' import legacy from 'vite-plugin-legacy-swc' export default defineConfig({ plugins: [ legacy({ targets: ['defaults', 'not IE 11'], modernTargets: ['edge>=79', 'firefox>=67', 'chrome>=64', 'safari>=12', 'chromeAndroid>=64', 'iOS>=12'] }), ], build: { // Ensure build.target is compatible with modernTargets if not explicitly overridden by the plugin target: 'esnext' } })
Debug
Known issues
breakingThe package transitioned to ESM-only in v2.0.0. CommonJS `require()` statements will no longer work.
fix
Migrate all import statements to use ES Modules syntax (e.g., `import legacy from 'vite-plugin-legacy-swc'`).
affects: >=2.0.0
breakingThe `location.protocol!="file:"` condition for modern Android webview was removed in v2.0.0. This change aligns with upstream Vite behavior but might affect specific deployment environments, particularly those involving local file protocols.
fix
Review existing deployments or configurations that rely on specific behavior related to file protocols in modern Android webviews.
affects: >=2.0.0
gotchaThe `modernTargets` option within the plugin configuration will override Vite's `build.target` option when the plugin collects polyfills for modern chunks. Be aware of this interaction to avoid unintended transpilation levels or missing polyfills.
fix
Ensure `modernTargets` is explicitly configured to reflect desired modern browser support. If `build.target` is also set, ensure it's compatible or understand that `modernTargets` will take precedence for polyfill collection.
affects: >=2.0.0
gotchaThere's a distinction between the `targets` option (used for transpiling legacy chunks with SWC) and `modernTargets` (used for collecting polyfills for modern chunks). Misconfiguring these can lead to incorrect browser support or inflated bundle sizes.
fix
Carefully define `targets` to cover the range of legacy browsers needing transpilation, and `modernTargets` to represent the baseline for modern browsers that will receive un-transpiled code but may still need polyfills.
affects: >=1.0.0
Errors
Common errors & fixes
require is not defined
Attempting to use CommonJS `require()` syntax after upgrading to v2.0.0, which is ESM-only.
fix
Update your import statements to use ES Modules syntax: `import legacy from 'vite-plugin-legacy-swc'` in your `vite.config.js`.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
viterequiredPeer dependency for Vite integration.
Agent activity
2 hits · last 30 days
node
2
Resources
vite-plugin-legacy-swc — npm install vite-plugin-legacy-swc · libregistry