@vitejs/plugin-legacy 8.0.0 → 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/dist/index.js +16 -5
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -100,11 +100,21 @@ const legacyPolyfillId = "vite-legacy-polyfill";
|
|
|
100
100
|
const legacyEntryId = "vite-legacy-entry";
|
|
101
101
|
const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`;
|
|
102
102
|
const detectModernBrowserVarName = "__vite_is_modern_browser";
|
|
103
|
-
|
|
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")`;
|
|
104
114
|
const detectModernBrowserDetector = `import.meta.url;import("_").catch(()=>1);(async function*(){})().next()`;
|
|
105
|
-
const detectModernBrowserCode = `import'${
|
|
115
|
+
const detectModernBrowserCode = `import'${createDetectImportMetaResolveSupportModule(null)}';${detectModernBrowserDetector};window.${detectModernBrowserVarName}=true`;
|
|
106
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)}();`;
|
|
107
|
-
const
|
|
117
|
+
const createModernChunkLegacyGuard = (chunkId) => `import'${createDetectImportMetaResolveSupportModule(chunkId)}';export function __vite_legacy_guard(){${detectModernBrowserDetector}};`;
|
|
108
118
|
//#endregion
|
|
109
119
|
//#region src/index.ts
|
|
110
120
|
let babel;
|
|
@@ -294,7 +304,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
294
304
|
if (!isLegacyChunk(chunk)) {
|
|
295
305
|
if (options.modernPolyfills && !Array.isArray(options.modernPolyfills) && genModern) await detectPolyfills(raw, modernTargets, assumptions, polyfillsDiscovered.modern);
|
|
296
306
|
const ms = new MagicString(raw);
|
|
297
|
-
if (genLegacy && chunk.isEntry) ms.prepend(
|
|
307
|
+
if (genLegacy && chunk.isEntry) ms.prepend(createModernChunkLegacyGuard(chunk.fileName));
|
|
298
308
|
if (raw.includes(legacyEnvVarMarker)) {
|
|
299
309
|
const re = new RegExp(legacyEnvVarMarker, "g");
|
|
300
310
|
let match;
|
|
@@ -534,7 +544,8 @@ function prependModenChunkLegacyGuardPlugin() {
|
|
|
534
544
|
configResolved(config) {
|
|
535
545
|
sourceMapEnabled = !!config.build.sourcemap;
|
|
536
546
|
},
|
|
537
|
-
renderChunk(code) {
|
|
547
|
+
renderChunk(code, chunk) {
|
|
548
|
+
const modernChunkLegacyGuard = createModernChunkLegacyGuard(chunk.fileName);
|
|
538
549
|
if (!sourceMapEnabled) return modernChunkLegacyGuard + code;
|
|
539
550
|
const ms = new MagicString(code);
|
|
540
551
|
ms.prepend(modernChunkLegacyGuard);
|
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,12 +31,12 @@
|
|
|
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"
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
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,
|