@vitejs/plugin-legacy 7.1.0 → 7.2.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
@@ -40,7 +40,7 @@ npm add -D terser
40
40
  - **Type:** `string | string[] | { [key: string]: string }`
41
41
  - **Default:** [`'last 2 versions and not dead, > 0.3%, Firefox ESR'`](https://browsersl.ist/#q=last+2+versions+and+not+dead%2C+%3E+0.3%25%2C+Firefox+ESR)
42
42
 
43
- If explicitly set, it's passed on to [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env#targets) when rendering **legacy chunks**.
43
+ It's passed on to [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env#targets) when rendering **legacy chunks**.
44
44
 
45
45
  The query is also [Browserslist compatible](https://github.com/browserslist/browserslist). See [Browserslist Best Practices](https://github.com/browserslist/browserslist#best-practices) for more details.
46
46
 
@@ -51,12 +51,14 @@ npm add -D terser
51
51
  - **Type:** `string | string[]`
52
52
  - **Default:** [`'edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12'`](https://browsersl.ist/#q=edge%3E%3D79%2C+firefox%3E%3D67%2C+chrome%3E%3D64%2C+safari%3E%3D12%2C+chromeAndroid%3E%3D64%2C+iOS%3E%3D12)
53
53
 
54
- If explicitly set, it's passed on to [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env#targets) when rendering **modern chunks**.
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
 
56
56
  The query is also [Browserslist compatible](https://github.com/browserslist/browserslist). See [Browserslist Best Practices](https://github.com/browserslist/browserslist#best-practices) for more details.
57
57
 
58
58
  If it's not set, plugin-legacy will fallback to the default value.
59
59
 
60
+ Note that this options should not be set unless `renderLegacyChunks` is set to `false`.
61
+
60
62
  ### `polyfills`
61
63
 
62
64
  - **Type:** `boolean | string[]`
package/dist/index.d.ts CHANGED
@@ -46,4 +46,4 @@ declare function detectPolyfills(code: string, targets: any, assumptions: Record
46
46
  declare const cspHashes: string[];
47
47
  declare function viteLegacyPluginCjs(this: unknown, options: Options): Plugin[];
48
48
  //#endregion
49
- export { Options, cspHashes, viteLegacyPlugin as default, detectPolyfills, viteLegacyPluginCjs as "module.exports" };
49
+ export { type Options, cspHashes, viteLegacyPlugin as default, detectPolyfills, viteLegacyPluginCjs as "module.exports" };
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
34
34
 
35
35
  //#endregion
36
36
  //#region ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
37
- var require_picocolors = __commonJS({ "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
37
+ var require_picocolors = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js": ((exports, module) => {
38
38
  let p = process || {}, argv = p.argv || [], env = p.env || {};
39
39
  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);
40
40
  let formatter = (open, close, replace = open) => (input) => {
@@ -99,7 +99,7 @@ var require_picocolors = __commonJS({ "../../node_modules/.pnpm/picocolors@1.1.1
99
99
  };
100
100
  module.exports = createColors();
101
101
  module.exports.createColors = createColors;
102
- } });
102
+ }) });
103
103
 
104
104
  //#endregion
105
105
  //#region src/snippets.ts
@@ -115,7 +115,7 @@ const modernChunkLegacyGuard = `export function __vite_legacy_guard(){${detectMo
115
115
 
116
116
  //#endregion
117
117
  //#region src/index.ts
118
- var import_picocolors = __toESM(require_picocolors(), 1);
118
+ var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
119
119
  let babel;
120
120
  async function loadBabel() {
121
121
  return babel ??= import("@babel/core");
@@ -157,6 +157,14 @@ const legacyEnvVarMarker = `__VITE_IS_LEGACY__`;
157
157
  const _require = createRequire(import.meta.url);
158
158
  const nonLeadingHashInFileNameRE = /[^/]+\[hash(?::\d+)?\]/;
159
159
  const prefixedHashInFileNameRE = /\W?\[hash(?::\d+)?\]/;
160
+ const modernTargetsEsbuild = [
161
+ "es2020",
162
+ "edge79",
163
+ "firefox67",
164
+ "chrome64",
165
+ "safari12"
166
+ ];
167
+ const modernTargetsBabel = "edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12";
160
168
  function viteLegacyPlugin(options = {}) {
161
169
  if ("rolldownVersion" in vite) {
162
170
  const { default: viteLegacyPluginForRolldownVite } = _require("#legacy-for-rolldown-vite");
@@ -164,15 +172,7 @@ function viteLegacyPlugin(options = {}) {
164
172
  }
165
173
  let config;
166
174
  let targets;
167
- let modernTargets;
168
- const modernTargetsEsbuild = [
169
- "es2020",
170
- "edge79",
171
- "firefox67",
172
- "chrome64",
173
- "safari12"
174
- ];
175
- const modernTargetsBabel = "edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12";
175
+ const modernTargets = options.modernTargets || modernTargetsBabel;
176
176
  const genLegacy = options.renderLegacyChunks !== false;
177
177
  const genModern = options.renderModernChunks !== false;
178
178
  if (!genLegacy && !genModern) throw new Error("`renderLegacyChunks` and `renderModernChunks` cannot be both false");
@@ -199,6 +199,7 @@ function viteLegacyPlugin(options = {}) {
199
199
  legacyPolyfills.add(i);
200
200
  });
201
201
  let overriddenBuildTarget = false;
202
+ let overriddenBuildTargetOnlyModern = false;
202
203
  let overriddenDefaultModernTargets = false;
203
204
  const legacyConfigPlugin = {
204
205
  name: "vite:legacy-config",
@@ -209,16 +210,17 @@ function viteLegacyPlugin(options = {}) {
209
210
  if (genLegacy) {
210
211
  overriddenBuildTarget = config$1.build.target !== void 0;
211
212
  overriddenDefaultModernTargets = options.modernTargets !== void 0;
212
- if (options.modernTargets) {
213
- const { default: browserslistToEsbuild } = await import("browserslist-to-esbuild");
214
- config$1.build.target = browserslistToEsbuild(options.modernTargets);
215
- } else config$1.build.target = modernTargetsEsbuild;
216
- }
213
+ } else overriddenBuildTargetOnlyModern = config$1.build.target !== void 0;
214
+ if (options.modernTargets) {
215
+ const { default: browserslistToEsbuild } = await import("browserslist-to-esbuild");
216
+ config$1.build.target = browserslistToEsbuild(options.modernTargets);
217
+ } else config$1.build.target = modernTargetsEsbuild;
217
218
  }
218
219
  return { define: { "import.meta.env.LEGACY": env$1.command === "serve" || config$1.build?.ssr ? false : legacyEnvVarMarker } };
219
220
  },
220
221
  configResolved(config$1) {
221
222
  if (overriddenBuildTarget) config$1.logger.warn(import_picocolors.default.yellow(`plugin-legacy overrode 'build.target'. You should pass 'targets' as an option to this plugin with the list of legacy browsers to support instead.`));
223
+ if (overriddenBuildTargetOnlyModern) config$1.logger.warn(import_picocolors.default.yellow(`plugin-legacy overrode 'build.target'. You should pass 'modernTargets' as an option to this plugin with the list of browsers to support instead.`));
222
224
  if (overriddenDefaultModernTargets) config$1.logger.warn(import_picocolors.default.yellow(`plugin-legacy 'modernTargets' option overrode the builtin targets of modern chunks. Some versions of browsers between legacy and modern may not be supported.`));
223
225
  if (config$1.isWorker) config$1.logger.warn(import_picocolors.default.yellow(`plugin-legacy should not be passed to 'worker.plugins'. Pass to 'plugins' instead. Note that generating legacy chunks for workers are not supported by plugin-legacy.`));
224
226
  }
@@ -256,7 +258,6 @@ function viteLegacyPlugin(options = {}) {
256
258
  configResolved(_config) {
257
259
  if (_config.build.lib) throw new Error("@vitejs/plugin-legacy does not support library mode.");
258
260
  config = _config;
259
- modernTargets = options.modernTargets || modernTargetsBabel;
260
261
  if (isDebug) console.log(`[@vitejs/plugin-legacy] modernTargets:`, modernTargets);
261
262
  if (!genLegacy || config.build.ssr) return;
262
263
  targets = options.targets || browserslistLoadConfig({ path: config.root }) || "last 2 versions and not dead, > 0.3%, Firefox ESR";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-legacy",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -42,7 +42,7 @@
42
42
  "babel-plugin-polyfill-regenerator": "^0.6.5",
43
43
  "browserslist": "^4.25.1",
44
44
  "browserslist-to-esbuild": "^2.1.1",
45
- "core-js": "^3.44.0",
45
+ "core-js": "^3.45.0",
46
46
  "magic-string": "^0.30.17",
47
47
  "regenerator-runtime": "^0.14.1",
48
48
  "systemjs": "^6.15.1"
@@ -56,8 +56,8 @@
56
56
  "acorn": "^8.15.0",
57
57
  "fdir": "^6.4.6",
58
58
  "picocolors": "^1.1.1",
59
- "tsdown": "^0.12.9",
60
- "vite": "7.0.5"
59
+ "tsdown": "^0.13.3",
60
+ "vite": "7.1.0"
61
61
  },
62
62
  "scripts": {
63
63
  "dev": "tsdown --watch",