@vitejs/plugin-legacy 8.0.0-beta.2 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/index.js +29 -30
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vitejs/plugin-legacy [](https://npmjs.com/package/@vitejs/plugin-legacy)
|
|
2
2
|
|
|
3
|
-
Vite's
|
|
3
|
+
Vite's minimum browser support target is [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import), and [`import.meta`](https://caniuse.com/mdn-javascript_operators_import_meta). This plugin provides support for legacy browsers that do not support those features when building for production.
|
|
4
4
|
|
|
5
5
|
By default, this plugin will:
|
|
6
6
|
|
|
@@ -49,7 +49,7 @@ npm add -D terser
|
|
|
49
49
|
### `modernTargets`
|
|
50
50
|
|
|
51
51
|
- **Type:** `string | string[]`
|
|
52
|
-
- **Default:** [`'edge>=
|
|
52
|
+
- **Default:** [`'edge>=105, firefox>=106, chrome>=105, safari>=16.4, chromeAndroid>=105, iOS>=16.4'`](https://browsersl.ist/#q=edge%3E%3D105%2C+firefox%3E%3D106%2C+chrome%3E%3D105%2C+safari%3E%3D16.4%2C+chromeAndroid%3E%3D105%2C+iOS%3E%3D16.4)
|
|
53
53
|
|
|
54
54
|
It's passed on to [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env#targets) when collecting polyfills for **modern chunks**. The value set here will override the `build.target` option.
|
|
55
55
|
|
|
@@ -135,16 +135,16 @@ npm add -D terser
|
|
|
135
135
|
|
|
136
136
|
## Browsers that supports ESM but does not support widely-available features
|
|
137
137
|
|
|
138
|
-
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
|
|
138
|
+
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:
|
|
139
139
|
|
|
140
140
|
- Modern bundle is downloaded in all ESM browsers
|
|
141
|
-
- Modern bundle throws
|
|
141
|
+
- Modern bundle throws an error in browsers without those features support
|
|
142
142
|
|
|
143
|
-
The following
|
|
143
|
+
The following features are considered as widely-available:
|
|
144
144
|
|
|
145
145
|
- dynamic import
|
|
146
|
-
- `import.meta`
|
|
147
146
|
- async generator
|
|
147
|
+
- `import.meta.resolve`
|
|
148
148
|
|
|
149
149
|
## Polyfill Specifiers
|
|
150
150
|
|
|
@@ -183,7 +183,7 @@ The current values are:
|
|
|
183
183
|
|
|
184
184
|
- `sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=`
|
|
185
185
|
- `sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=`
|
|
186
|
-
- `sha256-
|
|
186
|
+
- `sha256-w36slEqa9euNKxfvkw+LLGsDIr++3rsZXpZxtmRh8Aw=`
|
|
187
187
|
- `sha256-+5XkZFazzJo8n0iOP4ti/cLCMUudTf//Mzkb7xNPXIc=`
|
|
188
188
|
|
|
189
189
|
<!--
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { build, normalizePath } from "vite";
|
|
6
6
|
import MagicString from "magic-string";
|
|
7
7
|
import browserslist from "browserslist";
|
|
8
|
-
|
|
9
8
|
//#region \0rolldown/runtime.js
|
|
10
9
|
var __create = Object.create;
|
|
11
10
|
var __defProp = Object.defineProperty;
|
|
@@ -15,16 +14,12 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
15
14
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
15
|
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
17
16
|
var __copyProps = (to, from, except, desc) => {
|
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
18
|
+
key = keys[i];
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
20
|
+
get: ((k) => from[k]).bind(null, key),
|
|
21
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
22
|
+
});
|
|
28
23
|
}
|
|
29
24
|
return to;
|
|
30
25
|
};
|
|
@@ -32,10 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
27
|
value: mod,
|
|
33
28
|
enumerable: true
|
|
34
29
|
}) : target, mod));
|
|
35
|
-
|
|
36
30
|
//#endregion
|
|
37
|
-
//#region
|
|
38
|
-
var
|
|
31
|
+
//#region src/snippets.ts
|
|
32
|
+
var import_picocolors = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
39
33
|
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
40
34
|
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
41
35
|
let formatter = (open, close, replace = open) => (input) => {
|
|
@@ -100,21 +94,17 @@ var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
100
94
|
};
|
|
101
95
|
module.exports = createColors();
|
|
102
96
|
module.exports.createColors = createColors;
|
|
103
|
-
}));
|
|
104
|
-
|
|
105
|
-
//#endregion
|
|
106
|
-
//#region src/snippets.ts
|
|
107
|
-
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
97
|
+
})))(), 1);
|
|
108
98
|
const safari10NoModuleFix = `!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",(function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()}),!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();`;
|
|
109
99
|
const legacyPolyfillId = "vite-legacy-polyfill";
|
|
110
100
|
const legacyEntryId = "vite-legacy-entry";
|
|
111
101
|
const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`;
|
|
112
102
|
const detectModernBrowserVarName = "__vite_is_modern_browser";
|
|
103
|
+
const detectImportMetaResolveSupportModule = "data:text/javascript,if(!import.meta.resolve)throw Error(\"import.meta.resolve not supported\")";
|
|
113
104
|
const detectModernBrowserDetector = `import.meta.url;import("_").catch(()=>1);(async function*(){})().next()`;
|
|
114
|
-
const detectModernBrowserCode =
|
|
105
|
+
const detectModernBrowserCode = `import'${detectImportMetaResolveSupportModule}';${detectModernBrowserDetector};window.${detectModernBrowserVarName}=true`;
|
|
115
106
|
const dynamicFallbackInlineCode = `!function(){if(window.${detectModernBrowserVarName})return;console.warn("vite: loading legacy chunks, syntax error above and the same error below should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}();`;
|
|
116
|
-
const modernChunkLegacyGuard = `export function __vite_legacy_guard(){${detectModernBrowserDetector}};`;
|
|
117
|
-
|
|
107
|
+
const modernChunkLegacyGuard = `import'${detectImportMetaResolveSupportModule}';export function __vite_legacy_guard(){${detectModernBrowserDetector}};`;
|
|
118
108
|
//#endregion
|
|
119
109
|
//#region src/index.ts
|
|
120
110
|
let babel;
|
|
@@ -155,17 +145,19 @@ function toAssetPathFromHtml(filename, htmlPath, config) {
|
|
|
155
145
|
return toOutputFilePathInHtml(filename, "asset", htmlPath, "html", config, toRelative);
|
|
156
146
|
}
|
|
157
147
|
const legacyEnvVarMarker = `__VITE_IS_LEGACY__`;
|
|
148
|
+
const modernEnvVarMarker = `__VITE_IS_MODERN__`;
|
|
158
149
|
const _require = createRequire(import.meta.url);
|
|
159
150
|
const nonLeadingHashInFileNameRE = /[^/]+\[hash(?::\d+)?\]/;
|
|
160
151
|
const prefixedHashInFileNameRE = /\W?\[hash(?::\d+)?\]/;
|
|
161
152
|
const modernTargetsEsbuild = [
|
|
162
153
|
"es2020",
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
"
|
|
154
|
+
"edge105",
|
|
155
|
+
"firefox106",
|
|
156
|
+
"chrome105",
|
|
157
|
+
"safari16.4",
|
|
158
|
+
"ios16.4"
|
|
167
159
|
];
|
|
168
|
-
const modernTargetsBabel = "edge>=
|
|
160
|
+
const modernTargetsBabel = "edge>=105, firefox>=106, chrome>=105, safari>=16.4, chromeAndroid>=105, iOS>=16.4";
|
|
169
161
|
const outputOptionsForLegacyChunks = /* @__PURE__ */ new WeakSet();
|
|
170
162
|
function viteLegacyPlugin(options = {}) {
|
|
171
163
|
let config;
|
|
@@ -340,6 +332,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
340
332
|
presets: [[() => ({ plugins: [
|
|
341
333
|
recordAndRemovePolyfillBabelPlugin(polyfillsDiscovered.legacy),
|
|
342
334
|
replaceLegacyEnvBabelPlugin(),
|
|
335
|
+
replaceModernEnvBabelPlugin(),
|
|
343
336
|
wrapIIFEBabelPlugin()
|
|
344
337
|
] })], [(await import("@babel/preset-env")).default, {
|
|
345
338
|
bugfixes: true,
|
|
@@ -580,6 +573,14 @@ function replaceLegacyEnvBabelPlugin() {
|
|
|
580
573
|
} }
|
|
581
574
|
});
|
|
582
575
|
}
|
|
576
|
+
function replaceModernEnvBabelPlugin() {
|
|
577
|
+
return ({ types: t }) => ({
|
|
578
|
+
name: "vite-replace-env-modern",
|
|
579
|
+
visitor: { Identifier(path) {
|
|
580
|
+
if (path.node.name === modernEnvVarMarker) path.replaceWith(t.booleanLiteral(false));
|
|
581
|
+
} }
|
|
582
|
+
});
|
|
583
|
+
}
|
|
583
584
|
function wrapIIFEBabelPlugin() {
|
|
584
585
|
return ({ types: t, template }) => {
|
|
585
586
|
const buildIIFE = template(";(function(){%%body%%})();");
|
|
@@ -600,7 +601,6 @@ const cspHashes = [
|
|
|
600
601
|
detectModernBrowserCode,
|
|
601
602
|
dynamicFallbackInlineCode
|
|
602
603
|
].map((i) => crypto.hash("sha256", i, "base64"));
|
|
603
|
-
var src_default = viteLegacyPlugin;
|
|
604
604
|
function viteLegacyPluginCjs(options) {
|
|
605
605
|
return viteLegacyPlugin.call(this, options);
|
|
606
606
|
}
|
|
@@ -609,6 +609,5 @@ Object.assign(viteLegacyPluginCjs, {
|
|
|
609
609
|
default: viteLegacyPluginCjs,
|
|
610
610
|
detectPolyfills
|
|
611
611
|
});
|
|
612
|
-
|
|
613
612
|
//#endregion
|
|
614
|
-
export { cspHashes,
|
|
613
|
+
export { cspHashes, viteLegacyPlugin as default, detectPolyfills, viteLegacyPluginCjs as "module.exports" };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-legacy",
|
|
3
|
-
"version": "8.0.0
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Evan You",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"@babel/plugin-transform-dynamic-import": "^7.27.1",
|
|
33
33
|
"@babel/plugin-transform-modules-systemjs": "^7.29.0",
|
|
34
34
|
"@babel/preset-env": "^7.29.0",
|
|
35
|
-
"babel-plugin-polyfill-corejs3": "^0.14.
|
|
36
|
-
"babel-plugin-polyfill-regenerator": "^0.6.
|
|
35
|
+
"babel-plugin-polyfill-corejs3": "^0.14.1",
|
|
36
|
+
"babel-plugin-polyfill-regenerator": "^0.6.7",
|
|
37
37
|
"browserslist": "^4.28.1",
|
|
38
38
|
"browserslist-to-esbuild": "^2.1.1",
|
|
39
39
|
"core-js": "^3.48.0",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"terser": "^5.16.0",
|
|
46
|
-
"vite": "^
|
|
46
|
+
"vite": "^8.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"acorn": "^8.
|
|
49
|
+
"acorn": "^8.16.0",
|
|
50
50
|
"picocolors": "^1.1.1",
|
|
51
|
-
"tsdown": "^0.20.
|
|
52
|
-
"vite": "8.0.0
|
|
51
|
+
"tsdown": "^0.20.3",
|
|
52
|
+
"vite": "8.0.0"
|
|
53
53
|
},
|
|
54
54
|
"compatiblePackages": {
|
|
55
55
|
"schemaVersion": 1,
|