@vitejs/plugin-legacy 5.3.1 → 5.4.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
@@ -49,7 +49,7 @@ npm add -D terser
49
49
  ### `modernTargets`
50
50
 
51
51
  - **Type:** `string | string[]`
52
- - **Default:** [`'edge>=80, firefox>=72, chrome>=80, safari>=13.1, chromeAndroid>=80, iOS>=13.1'`](https://browsersl.ist/#q=edge%3E%3D80%2C+firefox%3E%3D72%2C+chrome%3E%3D80%2C+safari%3E%3D13.1%2C+chromeAndroid%3E%3D80%2C+iOS%3E%3D13.1)
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
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**.
55
55
 
@@ -74,7 +74,11 @@ npm add -D terser
74
74
 
75
75
  Add custom imports to the legacy polyfills chunk. Since the usage-based polyfill detection only covers ES language features, it may be necessary to manually specify additional DOM API polyfills using this option.
76
76
 
77
- Note: if additional polyfills are needed for both the modern and legacy chunks, they can simply be imported in the application source code.
77
+ ### `additionalModernPolyfills`
78
+
79
+ - **Type:** `string[]`
80
+
81
+ Add custom imports to the modern polyfills chunk. Since the usage-based polyfill detection only covers ES language features, it may be necessary to manually specify additional DOM API polyfills using this option.
78
82
 
79
83
  ### `modernPolyfills`
80
84
 
package/dist/index.cjs CHANGED
@@ -10,7 +10,6 @@ const vite = require('vite');
10
10
  const MagicString = require('magic-string');
11
11
  const require$$0 = require('tty');
12
12
  const browserslist = require('browserslist');
13
- const esbuildPluginBrowserslist = require('esbuild-plugin-browserslist');
14
13
 
15
14
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
16
15
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -168,7 +167,7 @@ function viteLegacyPlugin(options = {}) {
168
167
  "chrome64",
169
168
  "safari12"
170
169
  ];
171
- const modernTargetsBabel = "edge>=80, firefox>=72, chrome>=80, safari>=13.1, chromeAndroid>=80, iOS>=13.1";
170
+ const modernTargetsBabel = "edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12";
172
171
  const genLegacy = options.renderLegacyChunks !== false;
173
172
  const genModern = options.renderModernChunks !== false;
174
173
  if (!genLegacy && !genModern) {
@@ -190,6 +189,11 @@ function viteLegacyPlugin(options = {}) {
190
189
  );
191
190
  });
192
191
  }
192
+ if (Array.isArray(options.additionalModernPolyfills)) {
193
+ options.additionalModernPolyfills.forEach((i) => {
194
+ modernPolyfills.add(i);
195
+ });
196
+ }
193
197
  if (Array.isArray(options.polyfills)) {
194
198
  options.polyfills.forEach((i) => {
195
199
  if (i.startsWith(`regenerator`)) {
@@ -210,7 +214,7 @@ function viteLegacyPlugin(options = {}) {
210
214
  let overriddenDefaultModernTargets = false;
211
215
  const legacyConfigPlugin = {
212
216
  name: "vite:legacy-config",
213
- config(config2, env) {
217
+ async config(config2, env) {
214
218
  if (env.command === "build" && !config2.build?.ssr) {
215
219
  if (!config2.build) {
216
220
  config2.build = {};
@@ -221,7 +225,12 @@ function viteLegacyPlugin(options = {}) {
221
225
  if (genLegacy) {
222
226
  overriddenBuildTarget = config2.build.target !== void 0;
223
227
  overriddenDefaultModernTargets = options.modernTargets !== void 0;
224
- config2.build.target = options.modernTargets ? esbuildPluginBrowserslist.resolveToEsbuildTarget(browserslist__default(options.modernTargets)) : modernTargetsEsbuild;
228
+ if (options.modernTargets) {
229
+ const { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');
230
+ config2.build.target = browserslistToEsbuild(options.modernTargets);
231
+ } else {
232
+ config2.build.target = modernTargetsEsbuild;
233
+ }
225
234
  }
226
235
  }
227
236
  return {
@@ -316,13 +325,13 @@ function viteLegacyPlugin(options = {}) {
316
325
  throw new Error("@vitejs/plugin-legacy does not support library mode.");
317
326
  }
318
327
  config = _config;
328
+ modernTargets = options.modernTargets || modernTargetsBabel;
329
+ isDebug && console.log(`[@vitejs/plugin-legacy] modernTargets:`, modernTargets);
319
330
  if (!genLegacy || config.build.ssr) {
320
331
  return;
321
332
  }
322
333
  targets = options.targets || browserslistLoadConfig({ path: config.root }) || "last 2 versions and not dead, > 0.3%, Firefox ESR";
323
334
  isDebug && console.log(`[@vitejs/plugin-legacy] targets:`, targets);
324
- modernTargets = options.modernTargets || modernTargetsBabel;
325
- isDebug && console.log(`[@vitejs/plugin-legacy] modernTargets:`, modernTargets);
326
335
  const getLegacyOutputFileName = (fileNames, defaultFileName = "[name]-legacy-[hash].js") => {
327
336
  if (!fileNames) {
328
337
  return path__default.posix.join(config.build.assetsDir, defaultFileName);
package/dist/index.d.cts CHANGED
@@ -8,7 +8,7 @@ interface Options {
8
8
  [key: string]: string;
9
9
  };
10
10
  /**
11
- * default: 'edge>=80, firefox>=72, chrome>=80, safari>=13.1, chromeAndroid>=80, iOS>=13.1'
11
+ * default: 'edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12'
12
12
  */
13
13
  modernTargets?: string | string[];
14
14
  /**
@@ -16,6 +16,7 @@ interface Options {
16
16
  */
17
17
  polyfills?: boolean | string[];
18
18
  additionalLegacyPolyfills?: string[];
19
+ additionalModernPolyfills?: string[];
19
20
  /**
20
21
  * default: false
21
22
  */
package/dist/index.d.mts CHANGED
@@ -8,7 +8,7 @@ interface Options {
8
8
  [key: string]: string;
9
9
  };
10
10
  /**
11
- * default: 'edge>=80, firefox>=72, chrome>=80, safari>=13.1, chromeAndroid>=80, iOS>=13.1'
11
+ * default: 'edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12'
12
12
  */
13
13
  modernTargets?: string | string[];
14
14
  /**
@@ -16,6 +16,7 @@ interface Options {
16
16
  */
17
17
  polyfills?: boolean | string[];
18
18
  additionalLegacyPolyfills?: string[];
19
+ additionalModernPolyfills?: string[];
19
20
  /**
20
21
  * default: false
21
22
  */
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ interface Options {
8
8
  [key: string]: string;
9
9
  };
10
10
  /**
11
- * default: 'edge>=80, firefox>=72, chrome>=80, safari>=13.1, chromeAndroid>=80, iOS>=13.1'
11
+ * default: 'edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12'
12
12
  */
13
13
  modernTargets?: string | string[];
14
14
  /**
@@ -16,6 +16,7 @@ interface Options {
16
16
  */
17
17
  polyfills?: boolean | string[];
18
18
  additionalLegacyPolyfills?: string[];
19
+ additionalModernPolyfills?: string[];
19
20
  /**
20
21
  * default: false
21
22
  */
package/dist/index.mjs CHANGED
@@ -6,7 +6,6 @@ import { build, normalizePath } from 'vite';
6
6
  import MagicString from 'magic-string';
7
7
  import require$$0 from 'tty';
8
8
  import browserslist from 'browserslist';
9
- import { resolveToEsbuildTarget } from 'esbuild-plugin-browserslist';
10
9
 
11
10
  function getDefaultExportFromCjs (x) {
12
11
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -156,7 +155,7 @@ function viteLegacyPlugin(options = {}) {
156
155
  "chrome64",
157
156
  "safari12"
158
157
  ];
159
- const modernTargetsBabel = "edge>=80, firefox>=72, chrome>=80, safari>=13.1, chromeAndroid>=80, iOS>=13.1";
158
+ const modernTargetsBabel = "edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12";
160
159
  const genLegacy = options.renderLegacyChunks !== false;
161
160
  const genModern = options.renderModernChunks !== false;
162
161
  if (!genLegacy && !genModern) {
@@ -178,6 +177,11 @@ function viteLegacyPlugin(options = {}) {
178
177
  );
179
178
  });
180
179
  }
180
+ if (Array.isArray(options.additionalModernPolyfills)) {
181
+ options.additionalModernPolyfills.forEach((i) => {
182
+ modernPolyfills.add(i);
183
+ });
184
+ }
181
185
  if (Array.isArray(options.polyfills)) {
182
186
  options.polyfills.forEach((i) => {
183
187
  if (i.startsWith(`regenerator`)) {
@@ -198,7 +202,7 @@ function viteLegacyPlugin(options = {}) {
198
202
  let overriddenDefaultModernTargets = false;
199
203
  const legacyConfigPlugin = {
200
204
  name: "vite:legacy-config",
201
- config(config2, env) {
205
+ async config(config2, env) {
202
206
  if (env.command === "build" && !config2.build?.ssr) {
203
207
  if (!config2.build) {
204
208
  config2.build = {};
@@ -209,7 +213,12 @@ function viteLegacyPlugin(options = {}) {
209
213
  if (genLegacy) {
210
214
  overriddenBuildTarget = config2.build.target !== void 0;
211
215
  overriddenDefaultModernTargets = options.modernTargets !== void 0;
212
- config2.build.target = options.modernTargets ? resolveToEsbuildTarget(browserslist(options.modernTargets)) : modernTargetsEsbuild;
216
+ if (options.modernTargets) {
217
+ const { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');
218
+ config2.build.target = browserslistToEsbuild(options.modernTargets);
219
+ } else {
220
+ config2.build.target = modernTargetsEsbuild;
221
+ }
213
222
  }
214
223
  }
215
224
  return {
@@ -304,13 +313,13 @@ function viteLegacyPlugin(options = {}) {
304
313
  throw new Error("@vitejs/plugin-legacy does not support library mode.");
305
314
  }
306
315
  config = _config;
316
+ modernTargets = options.modernTargets || modernTargetsBabel;
317
+ isDebug && console.log(`[@vitejs/plugin-legacy] modernTargets:`, modernTargets);
307
318
  if (!genLegacy || config.build.ssr) {
308
319
  return;
309
320
  }
310
321
  targets = options.targets || browserslistLoadConfig({ path: config.root }) || "last 2 versions and not dead, > 0.3%, Firefox ESR";
311
322
  isDebug && console.log(`[@vitejs/plugin-legacy] targets:`, targets);
312
- modernTargets = options.modernTargets || modernTargetsBabel;
313
- isDebug && console.log(`[@vitejs/plugin-legacy] modernTargets:`, modernTargets);
314
323
  const getLegacyOutputFileName = (fileNames, defaultFileName = "[name]-legacy-[hash].js") => {
315
324
  if (!fileNames) {
316
325
  return path.posix.join(config.build.assetsDir, defaultFileName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-legacy",
3
- "version": "5.3.1",
3
+ "version": "5.4.0",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "files": [
@@ -35,14 +35,14 @@
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.23.9",
39
- "@babel/preset-env": "^7.23.9",
38
+ "@babel/core": "^7.24.5",
39
+ "@babel/preset-env": "^7.24.5",
40
40
  "browserslist": "^4.23.0",
41
- "core-js": "^3.36.0",
42
- "esbuild-plugin-browserslist": "^0.11.1",
43
- "magic-string": "^0.30.7",
41
+ "browserslist-to-esbuild": "^2.1.1",
42
+ "core-js": "^3.37.0",
43
+ "magic-string": "^0.30.10",
44
44
  "regenerator-runtime": "^0.14.1",
45
- "systemjs": "^6.14.3"
45
+ "systemjs": "^6.15.1"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "terser": "^5.4.0",
@@ -51,7 +51,7 @@
51
51
  "devDependencies": {
52
52
  "acorn": "^8.11.3",
53
53
  "picocolors": "^1.0.0",
54
- "vite": "5.1.4"
54
+ "vite": "5.2.11"
55
55
  },
56
56
  "scripts": {
57
57
  "dev": "unbuild --stub",