@vitejs/plugin-legacy 5.0.0-beta.1 → 5.0.0-beta.3

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 CHANGED
@@ -156,7 +156,7 @@ The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https
156
156
 
157
157
  - `sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=`
158
158
  - `sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=`
159
- - `sha256-4y/gEB2/KIwZFTfNqwXJq4olzvmQ0S214m9jwKgNXoc=`
159
+ - `sha256-8uUkKieevHiD3yYtzjkRvyDZWt+uZkBLuGEQWNiV3+c=`
160
160
  - `sha256-+5XkZFazzJo8n0iOP4ti/cLCMUudTf//Mzkb7xNPXIc=`
161
161
 
162
162
  <!--
package/dist/index.cjs CHANGED
@@ -92,7 +92,7 @@ const legacyPolyfillId = "vite-legacy-polyfill";
92
92
  const legacyEntryId = "vite-legacy-entry";
93
93
  const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`;
94
94
  const detectModernBrowserVarName = "__vite_is_modern_browser";
95
- const detectModernBrowserDetector = 'import.meta.url;import("_").catch(()=>1);async function* g(){};';
95
+ const detectModernBrowserDetector = 'import.meta.url;import("_").catch(()=>1);(async function* g(){})();';
96
96
  const detectModernBrowserCode = `${detectModernBrowserDetector}if(location.protocol!="file:"){window.${detectModernBrowserVarName}=true}`;
97
97
  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)}();`;
98
98
  const modernChunkLegacyGuard = `export function __vite_legacy_guard(){${detectModernBrowserDetector}};`;
@@ -267,12 +267,14 @@ function viteLegacyPlugin(options = {}) {
267
267
  if (!genLegacy) {
268
268
  return;
269
269
  }
270
- if (legacyPolyfills.size) {
270
+ if (options.polyfills !== false) {
271
271
  await detectPolyfills(
272
272
  `Promise.resolve(); Promise.all();`,
273
273
  targets,
274
274
  legacyPolyfills
275
275
  );
276
+ }
277
+ if (legacyPolyfills.size || !options.externalSystemJS) {
276
278
  isDebug && console.log(
277
279
  `[@vitejs/plugin-legacy] legacy polyfills:`,
278
280
  legacyPolyfills
@@ -314,8 +316,10 @@ function viteLegacyPlugin(options = {}) {
314
316
  let fileName = typeof fileNames === "function" ? fileNames(chunkInfo) : fileNames;
315
317
  if (fileName.includes("[name]")) {
316
318
  fileName = fileName.replace("[name]", "[name]-legacy");
319
+ } else if (fileName.includes("[hash]")) {
320
+ fileName = fileName.replace(/[.-]?\[hash\]/, "-legacy$&");
317
321
  } else {
318
- fileName = fileName.replace(/(.+)\.(.+)/, "$1-legacy.$2");
322
+ fileName = fileName.replace(/(.+?)\.(.+)/, "$1-legacy.$2");
319
323
  }
320
324
  return fileName;
321
325
  };
package/dist/index.d.cts CHANGED
@@ -34,4 +34,4 @@ declare function viteLegacyPlugin(options?: Options): Plugin[];
34
34
  declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
35
35
  declare const cspHashes: string[];
36
36
 
37
- export { cspHashes, viteLegacyPlugin as default, detectPolyfills };
37
+ export { type Options, cspHashes, viteLegacyPlugin as default, detectPolyfills };
package/dist/index.d.mts CHANGED
@@ -34,4 +34,4 @@ declare function viteLegacyPlugin(options?: Options): Plugin[];
34
34
  declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
35
35
  declare const cspHashes: string[];
36
36
 
37
- export { cspHashes, viteLegacyPlugin as default, detectPolyfills };
37
+ export { type Options, cspHashes, viteLegacyPlugin as default, detectPolyfills };
package/dist/index.d.ts CHANGED
@@ -34,4 +34,4 @@ declare function viteLegacyPlugin(options?: Options): Plugin[];
34
34
  declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
35
35
  declare const cspHashes: string[];
36
36
 
37
- export { cspHashes, viteLegacyPlugin as default, detectPolyfills };
37
+ export { type Options, cspHashes, viteLegacyPlugin as default, detectPolyfills };
package/dist/index.mjs CHANGED
@@ -80,7 +80,7 @@ const legacyPolyfillId = "vite-legacy-polyfill";
80
80
  const legacyEntryId = "vite-legacy-entry";
81
81
  const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`;
82
82
  const detectModernBrowserVarName = "__vite_is_modern_browser";
83
- const detectModernBrowserDetector = 'import.meta.url;import("_").catch(()=>1);async function* g(){};';
83
+ const detectModernBrowserDetector = 'import.meta.url;import("_").catch(()=>1);(async function* g(){})();';
84
84
  const detectModernBrowserCode = `${detectModernBrowserDetector}if(location.protocol!="file:"){window.${detectModernBrowserVarName}=true}`;
85
85
  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)}();`;
86
86
  const modernChunkLegacyGuard = `export function __vite_legacy_guard(){${detectModernBrowserDetector}};`;
@@ -255,12 +255,14 @@ function viteLegacyPlugin(options = {}) {
255
255
  if (!genLegacy) {
256
256
  return;
257
257
  }
258
- if (legacyPolyfills.size) {
258
+ if (options.polyfills !== false) {
259
259
  await detectPolyfills(
260
260
  `Promise.resolve(); Promise.all();`,
261
261
  targets,
262
262
  legacyPolyfills
263
263
  );
264
+ }
265
+ if (legacyPolyfills.size || !options.externalSystemJS) {
264
266
  isDebug && console.log(
265
267
  `[@vitejs/plugin-legacy] legacy polyfills:`,
266
268
  legacyPolyfills
@@ -302,8 +304,10 @@ function viteLegacyPlugin(options = {}) {
302
304
  let fileName = typeof fileNames === "function" ? fileNames(chunkInfo) : fileNames;
303
305
  if (fileName.includes("[name]")) {
304
306
  fileName = fileName.replace("[name]", "[name]-legacy");
307
+ } else if (fileName.includes("[hash]")) {
308
+ fileName = fileName.replace(/[.-]?\[hash\]/, "-legacy$&");
305
309
  } else {
306
- fileName = fileName.replace(/(.+)\.(.+)/, "$1-legacy.$2");
310
+ fileName = fileName.replace(/(.+?)\.(.+)/, "$1-legacy.$2");
307
311
  }
308
312
  return fileName;
309
313
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-legacy",
3
- "version": "5.0.0-beta.1",
3
+ "version": "5.0.0-beta.3",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "files": [
@@ -35,11 +35,11 @@
35
35
  "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
36
36
  "funding": "https://github.com/vitejs/vite?sponsor=1",
37
37
  "dependencies": {
38
- "@babel/core": "^7.22.20",
39
- "@babel/preset-env": "^7.22.20",
40
- "browserslist": "^4.21.11",
41
- "core-js": "^3.32.2",
42
- "magic-string": "^0.30.3",
38
+ "@babel/core": "^7.23.3",
39
+ "@babel/preset-env": "^7.23.3",
40
+ "browserslist": "^4.22.1",
41
+ "core-js": "^3.33.2",
42
+ "magic-string": "^0.30.5",
43
43
  "regenerator-runtime": "^0.14.0",
44
44
  "systemjs": "^6.14.2"
45
45
  },
@@ -48,9 +48,9 @@
48
48
  "vite": "^4.0.0"
49
49
  },
50
50
  "devDependencies": {
51
- "acorn": "^8.10.0",
51
+ "acorn": "^8.11.2",
52
52
  "picocolors": "^1.0.0",
53
- "vite": "5.0.0-beta.3"
53
+ "vite": "5.0.0-beta.19"
54
54
  },
55
55
  "scripts": {
56
56
  "dev": "unbuild --stub",