@vitejs/plugin-legacy 8.0.0-beta.3 → 8.0.1
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 +5 -5
- package/dist/index.js +32 -31
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -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
|
|
|
@@ -138,13 +138,13 @@ npm add -D terser
|
|
|
138
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,27 @@ 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
|
+
/**
|
|
104
|
+
* Create an inline module to detect if the browser supports import.meta.resolve
|
|
105
|
+
*
|
|
106
|
+
* This is an inline module to execute the code before other imports.
|
|
107
|
+
* Throwing an error can prevent the browser from executing the rest of the code.
|
|
108
|
+
*
|
|
109
|
+
* Note that due to a bug in Safari 15.x and below, each inline module has to be unique,
|
|
110
|
+
* otherwise Safari will only throw the error for the first time that module is imported.
|
|
111
|
+
* https://github.com/vitejs/vite/issues/22008
|
|
112
|
+
*/
|
|
113
|
+
const createDetectImportMetaResolveSupportModule = (chunkId) => `data:text/javascript,${chunkId != null ? `${JSON.stringify(chunkId)};` : ""}if(!import.meta.resolve)throw Error("import.meta.resolve not supported")`;
|
|
113
114
|
const detectModernBrowserDetector = `import.meta.url;import("_").catch(()=>1);(async function*(){})().next()`;
|
|
114
|
-
const detectModernBrowserCode =
|
|
115
|
+
const detectModernBrowserCode = `import'${createDetectImportMetaResolveSupportModule(null)}';${detectModernBrowserDetector};window.${detectModernBrowserVarName}=true`;
|
|
115
116
|
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
|
|
117
|
-
|
|
117
|
+
const createModernChunkLegacyGuard = (chunkId) => `import'${createDetectImportMetaResolveSupportModule(chunkId)}';export function __vite_legacy_guard(){${detectModernBrowserDetector}};`;
|
|
118
118
|
//#endregion
|
|
119
119
|
//#region src/index.ts
|
|
120
120
|
let babel;
|
|
@@ -161,12 +161,13 @@ const nonLeadingHashInFileNameRE = /[^/]+\[hash(?::\d+)?\]/;
|
|
|
161
161
|
const prefixedHashInFileNameRE = /\W?\[hash(?::\d+)?\]/;
|
|
162
162
|
const modernTargetsEsbuild = [
|
|
163
163
|
"es2020",
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
"
|
|
164
|
+
"edge105",
|
|
165
|
+
"firefox106",
|
|
166
|
+
"chrome105",
|
|
167
|
+
"safari16.4",
|
|
168
|
+
"ios16.4"
|
|
168
169
|
];
|
|
169
|
-
const modernTargetsBabel = "edge>=
|
|
170
|
+
const modernTargetsBabel = "edge>=105, firefox>=106, chrome>=105, safari>=16.4, chromeAndroid>=105, iOS>=16.4";
|
|
170
171
|
const outputOptionsForLegacyChunks = /* @__PURE__ */ new WeakSet();
|
|
171
172
|
function viteLegacyPlugin(options = {}) {
|
|
172
173
|
let config;
|
|
@@ -303,7 +304,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
303
304
|
if (!isLegacyChunk(chunk)) {
|
|
304
305
|
if (options.modernPolyfills && !Array.isArray(options.modernPolyfills) && genModern) await detectPolyfills(raw, modernTargets, assumptions, polyfillsDiscovered.modern);
|
|
305
306
|
const ms = new MagicString(raw);
|
|
306
|
-
if (genLegacy && chunk.isEntry) ms.prepend(
|
|
307
|
+
if (genLegacy && chunk.isEntry) ms.prepend(createModernChunkLegacyGuard(chunk.fileName));
|
|
307
308
|
if (raw.includes(legacyEnvVarMarker)) {
|
|
308
309
|
const re = new RegExp(legacyEnvVarMarker, "g");
|
|
309
310
|
let match;
|
|
@@ -543,7 +544,8 @@ function prependModenChunkLegacyGuardPlugin() {
|
|
|
543
544
|
configResolved(config) {
|
|
544
545
|
sourceMapEnabled = !!config.build.sourcemap;
|
|
545
546
|
},
|
|
546
|
-
renderChunk(code) {
|
|
547
|
+
renderChunk(code, chunk) {
|
|
548
|
+
const modernChunkLegacyGuard = createModernChunkLegacyGuard(chunk.fileName);
|
|
547
549
|
if (!sourceMapEnabled) return modernChunkLegacyGuard + code;
|
|
548
550
|
const ms = new MagicString(code);
|
|
549
551
|
ms.prepend(modernChunkLegacyGuard);
|
|
@@ -618,6 +620,5 @@ Object.assign(viteLegacyPluginCjs, {
|
|
|
618
620
|
default: viteLegacyPluginCjs,
|
|
619
621
|
detectPolyfills
|
|
620
622
|
});
|
|
621
|
-
|
|
622
623
|
//#endregion
|
|
623
|
-
export { cspHashes, viteLegacyPlugin as default, detectPolyfills, viteLegacyPluginCjs as "module.exports" };
|
|
624
|
+
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.
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Evan You",
|
|
@@ -31,25 +31,25 @@
|
|
|
31
31
|
"@babel/core": "^7.29.0",
|
|
32
32
|
"@babel/plugin-transform-dynamic-import": "^7.27.1",
|
|
33
33
|
"@babel/plugin-transform-modules-systemjs": "^7.29.0",
|
|
34
|
-
"@babel/preset-env": "^7.29.
|
|
35
|
-
"babel-plugin-polyfill-corejs3": "^0.14.
|
|
36
|
-
"babel-plugin-polyfill-regenerator": "^0.6.
|
|
34
|
+
"@babel/preset-env": "^7.29.2",
|
|
35
|
+
"babel-plugin-polyfill-corejs3": "^0.14.2",
|
|
36
|
+
"babel-plugin-polyfill-regenerator": "^0.6.8",
|
|
37
37
|
"browserslist": "^4.28.1",
|
|
38
38
|
"browserslist-to-esbuild": "^2.1.1",
|
|
39
|
-
"core-js": "^3.
|
|
39
|
+
"core-js": "^3.49.0",
|
|
40
40
|
"magic-string": "^0.30.21",
|
|
41
41
|
"regenerator-runtime": "^0.14.1",
|
|
42
42
|
"systemjs": "^6.15.1"
|
|
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.
|
|
52
|
-
"vite": "8.0.
|
|
51
|
+
"tsdown": "^0.21.4",
|
|
52
|
+
"vite": "8.0.3"
|
|
53
53
|
},
|
|
54
54
|
"compatiblePackages": {
|
|
55
55
|
"schemaVersion": 1,
|