@vitejs/plugin-legacy 7.0.0-beta.0 → 7.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 CHANGED
@@ -129,6 +129,8 @@ npm add -D terser
129
129
 
130
130
  Set to `false` to only output the legacy bundles that support all target browsers.
131
131
 
132
+ This is also useful when running the project locally using `file:` protocol, as loading modern chunks with `type="module"` may trigger CORS restrictions. To avoid this issue, simply set `renderModernChunks` to `false` to exclusively use legacy chunks instead.
133
+
132
134
  ## Browsers that supports ESM but does not support widely-available features
133
135
 
134
136
  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:
@@ -179,7 +181,7 @@ The current values are:
179
181
 
180
182
  - `sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=`
181
183
  - `sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=`
182
- - `sha256-VA8O2hAdooB288EpSTrGLl7z3QikbWU9wwoebO/QaYk=`
184
+ - `sha256-ZxAi3a7m9Mzbc+Z1LGuCCK5Xee6reDkEPRas66H9KSo=`
183
185
  - `sha256-+5XkZFazzJo8n0iOP4ti/cLCMUudTf//Mzkb7xNPXIc=`
184
186
 
185
187
  <!--
package/dist/index.d.ts CHANGED
@@ -38,12 +38,12 @@ interface Options {
38
38
  * default: {}
39
39
  */
40
40
  assumptions?: Record<string, boolean>;
41
- } //#endregion
41
+ }
42
+ //#endregion
42
43
  //#region src/index.d.ts
43
44
  declare function viteLegacyPlugin(options?: Options): Plugin[];
44
45
  declare function detectPolyfills(code: string, targets: any, assumptions: Record<string, boolean>, list: Set<string>): Promise<void>;
45
46
  declare const cspHashes: string[];
46
47
  declare function viteLegacyPluginCjs(this: unknown, options: Options): Plugin[];
47
-
48
48
  //#endregion
49
49
  export { Options, cspHashes, viteLegacyPlugin as default, detectPolyfills, viteLegacyPluginCjs as "module.exports" };
package/dist/index.js CHANGED
@@ -108,7 +108,7 @@ const legacyEntryId = "vite-legacy-entry";
108
108
  const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`;
109
109
  const detectModernBrowserVarName = "__vite_is_modern_browser";
110
110
  const detectModernBrowserDetector = `import.meta.url;import("_").catch(()=>1);(async function*(){})().next()`;
111
- const detectModernBrowserCode = `${detectModernBrowserDetector};if(location.protocol!="file:"){window.${detectModernBrowserVarName}=true}`;
111
+ const detectModernBrowserCode = `${detectModernBrowserDetector};window.${detectModernBrowserVarName}=true`;
112
112
  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)}();`;
113
113
  const modernChunkLegacyGuard = `export function __vite_legacy_guard(){${detectModernBrowserDetector}};`;
114
114
 
@@ -174,12 +174,12 @@ function viteLegacyPlugin(options = {}) {
174
174
  const debugFlags = (process.env.DEBUG || "").split(",");
175
175
  const isDebug = debugFlags.includes("vite:*") || debugFlags.includes("vite:legacy");
176
176
  const assumptions = options.assumptions || {};
177
- const facadeToLegacyChunkMap = new Map();
178
- const facadeToLegacyPolyfillMap = new Map();
179
- const facadeToModernPolyfillMap = new Map();
180
- const modernPolyfills = new Set();
181
- const legacyPolyfills = new Set();
182
- const outputToChunkFileNameToPolyfills = new WeakMap();
177
+ const facadeToLegacyChunkMap = /* @__PURE__ */ new Map();
178
+ const facadeToLegacyPolyfillMap = /* @__PURE__ */ new Map();
179
+ const facadeToModernPolyfillMap = /* @__PURE__ */ new Map();
180
+ const modernPolyfills = /* @__PURE__ */ new Set();
181
+ const legacyPolyfills = /* @__PURE__ */ new Set();
182
+ const outputToChunkFileNameToPolyfills = /* @__PURE__ */ new WeakMap();
183
183
  if (Array.isArray(options.modernPolyfills) && genModern) options.modernPolyfills.forEach((i) => {
184
184
  modernPolyfills.add(i.includes("/") ? `core-js/${i}` : `core-js/modules/${i}.js`);
185
185
  });
@@ -283,10 +283,10 @@ function viteLegacyPlugin(options = {}) {
283
283
  if (config.build.ssr) return null;
284
284
  let chunkFileNameToPolyfills = outputToChunkFileNameToPolyfills.get(opts);
285
285
  if (chunkFileNameToPolyfills == null) {
286
- chunkFileNameToPolyfills = new Map();
286
+ chunkFileNameToPolyfills = /* @__PURE__ */ new Map();
287
287
  for (const fileName in chunks) chunkFileNameToPolyfills.set(fileName, {
288
- modern: new Set(),
289
- legacy: new Set()
288
+ modern: /* @__PURE__ */ new Set(),
289
+ legacy: /* @__PURE__ */ new Set()
290
290
  });
291
291
  outputToChunkFileNameToPolyfills.set(opts, chunkFileNameToPolyfills);
292
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-legacy",
3
- "version": "7.0.0-beta.0",
3
+ "version": "7.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -28,24 +28,24 @@
28
28
  "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
29
29
  "funding": "https://github.com/vitejs/vite?sponsor=1",
30
30
  "dependencies": {
31
- "@babel/core": "^7.27.1",
31
+ "@babel/core": "^7.27.4",
32
32
  "@babel/preset-env": "^7.27.2",
33
- "browserslist": "^4.24.5",
33
+ "browserslist": "^4.25.0",
34
34
  "browserslist-to-esbuild": "^2.1.1",
35
- "core-js": "^3.42.0",
35
+ "core-js": "^3.43.0",
36
36
  "magic-string": "^0.30.17",
37
37
  "regenerator-runtime": "^0.14.1",
38
38
  "systemjs": "^6.15.1"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "terser": "^5.16.0",
42
- "vite": "^6.0.0"
42
+ "vite": "^7.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "acorn": "^8.14.1",
45
+ "acorn": "^8.15.0",
46
46
  "picocolors": "^1.1.1",
47
- "tsdown": "^0.11.12",
48
- "vite": "7.0.0-beta.0"
47
+ "tsdown": "^0.12.8",
48
+ "vite": "7.0.0"
49
49
  },
50
50
  "scripts": {
51
51
  "dev": "tsdown --watch",