@vitejs/plugin-legacy 5.3.2 → 5.4.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/README.md +8 -4
- package/dist/index.cjs +92 -43
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +92 -43
- package/package.json +9 -8
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>=
|
|
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
|
-
|
|
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
|
|
|
@@ -85,9 +89,9 @@ npm add -D terser
|
|
|
85
89
|
|
|
86
90
|
Set to a list of strings to explicitly control which polyfills to include. See [Polyfill Specifiers](#polyfill-specifiers) for details.
|
|
87
91
|
|
|
88
|
-
|
|
92
|
+
If `modernTargets` is not set, it is **not recommended** to use the `true` value (which uses auto-detection) because `core-js@3` is very aggressive in polyfill inclusions due to all the bleeding edge features it supports. Even when targeting native ESM support, it injects 15kb of polyfills!
|
|
89
93
|
|
|
90
|
-
If you don't have hard reliance on bleeding edge runtime features, it is not that hard to avoid having to use polyfills in the modern build altogether. Alternatively, consider using an on-demand service like [Polyfill.io](https://polyfill.io) to only inject necessary polyfills based on actual browser user-agents (most modern browsers will need nothing!).
|
|
94
|
+
If you don't have hard reliance on bleeding edge runtime features, it is not that hard to avoid having to use polyfills in the modern build altogether. Alternatively, consider setting `modernTargets` or using an on-demand service like [Polyfill.io](https://polyfill.io) to only inject necessary polyfills based on actual browser user-agents (most modern browsers will need nothing!).
|
|
91
95
|
|
|
92
96
|
### `renderLegacyChunks`
|
|
93
97
|
|
package/dist/index.cjs
CHANGED
|
@@ -23,17 +23,21 @@ function getDefaultExportFromCjs (x) {
|
|
|
23
23
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
function commonjsRequire(path) {
|
|
27
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
28
|
+
}
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
var picocolors = {exports: {}};
|
|
29
31
|
|
|
32
|
+
let argv = process.argv || [],
|
|
33
|
+
env = process.env;
|
|
30
34
|
let isColorSupported =
|
|
31
|
-
!("NO_COLOR" in
|
|
32
|
-
("FORCE_COLOR" in
|
|
33
|
-
|
|
35
|
+
!("NO_COLOR" in env || argv.includes("--no-color")) &&
|
|
36
|
+
("FORCE_COLOR" in env ||
|
|
37
|
+
argv.includes("--color") ||
|
|
34
38
|
process.platform === "win32" ||
|
|
35
|
-
(
|
|
36
|
-
"CI" in
|
|
39
|
+
(commonjsRequire != null && require$$0__default.isatty(1) && env.TERM !== "dumb") ||
|
|
40
|
+
"CI" in env);
|
|
37
41
|
|
|
38
42
|
let formatter =
|
|
39
43
|
(open, close, replace = open) =>
|
|
@@ -46,40 +50,47 @@ let formatter =
|
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
let replaceClose = (string, close, replace, index) => {
|
|
49
|
-
let
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
let result = "";
|
|
54
|
+
let cursor = 0;
|
|
55
|
+
do {
|
|
56
|
+
result += string.substring(cursor, index) + replace;
|
|
57
|
+
cursor = index + close.length;
|
|
58
|
+
index = string.indexOf(close, cursor);
|
|
59
|
+
} while (~index)
|
|
60
|
+
return result + string.substring(cursor)
|
|
53
61
|
};
|
|
54
62
|
|
|
55
|
-
let createColors = (enabled = isColorSupported) =>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
63
|
+
let createColors = (enabled = isColorSupported) => {
|
|
64
|
+
let init = enabled ? formatter : () => String;
|
|
65
|
+
return {
|
|
66
|
+
isColorSupported: enabled,
|
|
67
|
+
reset: init("\x1b[0m", "\x1b[0m"),
|
|
68
|
+
bold: init("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|
69
|
+
dim: init("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|
70
|
+
italic: init("\x1b[3m", "\x1b[23m"),
|
|
71
|
+
underline: init("\x1b[4m", "\x1b[24m"),
|
|
72
|
+
inverse: init("\x1b[7m", "\x1b[27m"),
|
|
73
|
+
hidden: init("\x1b[8m", "\x1b[28m"),
|
|
74
|
+
strikethrough: init("\x1b[9m", "\x1b[29m"),
|
|
75
|
+
black: init("\x1b[30m", "\x1b[39m"),
|
|
76
|
+
red: init("\x1b[31m", "\x1b[39m"),
|
|
77
|
+
green: init("\x1b[32m", "\x1b[39m"),
|
|
78
|
+
yellow: init("\x1b[33m", "\x1b[39m"),
|
|
79
|
+
blue: init("\x1b[34m", "\x1b[39m"),
|
|
80
|
+
magenta: init("\x1b[35m", "\x1b[39m"),
|
|
81
|
+
cyan: init("\x1b[36m", "\x1b[39m"),
|
|
82
|
+
white: init("\x1b[37m", "\x1b[39m"),
|
|
83
|
+
gray: init("\x1b[90m", "\x1b[39m"),
|
|
84
|
+
bgBlack: init("\x1b[40m", "\x1b[49m"),
|
|
85
|
+
bgRed: init("\x1b[41m", "\x1b[49m"),
|
|
86
|
+
bgGreen: init("\x1b[42m", "\x1b[49m"),
|
|
87
|
+
bgYellow: init("\x1b[43m", "\x1b[49m"),
|
|
88
|
+
bgBlue: init("\x1b[44m", "\x1b[49m"),
|
|
89
|
+
bgMagenta: init("\x1b[45m", "\x1b[49m"),
|
|
90
|
+
bgCyan: init("\x1b[46m", "\x1b[49m"),
|
|
91
|
+
bgWhite: init("\x1b[47m", "\x1b[49m"),
|
|
92
|
+
}
|
|
93
|
+
};
|
|
83
94
|
|
|
84
95
|
picocolors.exports = createColors();
|
|
85
96
|
picocolors.exports.createColors = createColors;
|
|
@@ -167,7 +178,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
167
178
|
"chrome64",
|
|
168
179
|
"safari12"
|
|
169
180
|
];
|
|
170
|
-
const modernTargetsBabel = "edge>=
|
|
181
|
+
const modernTargetsBabel = "edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12";
|
|
171
182
|
const genLegacy = options.renderLegacyChunks !== false;
|
|
172
183
|
const genModern = options.renderModernChunks !== false;
|
|
173
184
|
if (!genLegacy && !genModern) {
|
|
@@ -182,6 +193,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
182
193
|
const facadeToModernPolyfillMap = /* @__PURE__ */ new Map();
|
|
183
194
|
const modernPolyfills = /* @__PURE__ */ new Set();
|
|
184
195
|
const legacyPolyfills = /* @__PURE__ */ new Set();
|
|
196
|
+
const outputToChunkFileNameToPolyfills = /* @__PURE__ */ new WeakMap();
|
|
185
197
|
if (Array.isArray(options.modernPolyfills) && genModern) {
|
|
186
198
|
options.modernPolyfills.forEach((i) => {
|
|
187
199
|
modernPolyfills.add(
|
|
@@ -189,6 +201,11 @@ function viteLegacyPlugin(options = {}) {
|
|
|
189
201
|
);
|
|
190
202
|
});
|
|
191
203
|
}
|
|
204
|
+
if (Array.isArray(options.additionalModernPolyfills)) {
|
|
205
|
+
options.additionalModernPolyfills.forEach((i) => {
|
|
206
|
+
modernPolyfills.add(i);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
192
209
|
if (Array.isArray(options.polyfills)) {
|
|
193
210
|
options.polyfills.forEach((i) => {
|
|
194
211
|
if (i.startsWith(`regenerator`)) {
|
|
@@ -258,7 +275,16 @@ function viteLegacyPlugin(options = {}) {
|
|
|
258
275
|
if (config.build.ssr) {
|
|
259
276
|
return;
|
|
260
277
|
}
|
|
278
|
+
const chunkFileNameToPolyfills = outputToChunkFileNameToPolyfills.get(opts);
|
|
279
|
+
if (chunkFileNameToPolyfills == null) {
|
|
280
|
+
throw new Error(
|
|
281
|
+
"Internal @vitejs/plugin-legacy error: discovered polyfills should exist"
|
|
282
|
+
);
|
|
283
|
+
}
|
|
261
284
|
if (!isLegacyBundle(bundle, opts)) {
|
|
285
|
+
for (const { modern } of chunkFileNameToPolyfills.values()) {
|
|
286
|
+
modern.forEach((p) => modernPolyfills.add(p));
|
|
287
|
+
}
|
|
262
288
|
if (!modernPolyfills.size) {
|
|
263
289
|
return;
|
|
264
290
|
}
|
|
@@ -284,6 +310,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
284
310
|
if (!genLegacy) {
|
|
285
311
|
return;
|
|
286
312
|
}
|
|
313
|
+
for (const { legacy } of chunkFileNameToPolyfills.values()) {
|
|
314
|
+
legacy.forEach((p) => legacyPolyfills.add(p));
|
|
315
|
+
}
|
|
287
316
|
if (options.polyfills !== false) {
|
|
288
317
|
await detectPolyfills(
|
|
289
318
|
`Promise.resolve(); Promise.all();`,
|
|
@@ -315,6 +344,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
315
344
|
name: "vite:legacy-post-process",
|
|
316
345
|
enforce: "post",
|
|
317
346
|
apply: "build",
|
|
347
|
+
renderStart(opts) {
|
|
348
|
+
outputToChunkFileNameToPolyfills.set(opts, null);
|
|
349
|
+
},
|
|
318
350
|
configResolved(_config) {
|
|
319
351
|
if (_config.build.lib) {
|
|
320
352
|
throw new Error("@vitejs/plugin-legacy does not support library mode.");
|
|
@@ -365,13 +397,30 @@ function viteLegacyPlugin(options = {}) {
|
|
|
365
397
|
];
|
|
366
398
|
}
|
|
367
399
|
},
|
|
368
|
-
async renderChunk(raw, chunk, opts) {
|
|
400
|
+
async renderChunk(raw, chunk, opts, { chunks }) {
|
|
369
401
|
if (config.build.ssr) {
|
|
370
402
|
return null;
|
|
371
403
|
}
|
|
404
|
+
let chunkFileNameToPolyfills = outputToChunkFileNameToPolyfills.get(opts);
|
|
405
|
+
if (chunkFileNameToPolyfills == null) {
|
|
406
|
+
chunkFileNameToPolyfills = /* @__PURE__ */ new Map();
|
|
407
|
+
for (const fileName in chunks) {
|
|
408
|
+
chunkFileNameToPolyfills.set(fileName, {
|
|
409
|
+
modern: /* @__PURE__ */ new Set(),
|
|
410
|
+
legacy: /* @__PURE__ */ new Set()
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
outputToChunkFileNameToPolyfills.set(opts, chunkFileNameToPolyfills);
|
|
414
|
+
}
|
|
415
|
+
const polyfillsDiscovered = chunkFileNameToPolyfills.get(chunk.fileName);
|
|
416
|
+
if (polyfillsDiscovered == null) {
|
|
417
|
+
throw new Error(
|
|
418
|
+
`Internal @vitejs/plugin-legacy error: discovered polyfills for ${chunk.fileName} should exist`
|
|
419
|
+
);
|
|
420
|
+
}
|
|
372
421
|
if (!isLegacyChunk(chunk, opts)) {
|
|
373
422
|
if (options.modernPolyfills && !Array.isArray(options.modernPolyfills) && genModern) {
|
|
374
|
-
await detectPolyfills(raw, modernTargets,
|
|
423
|
+
await detectPolyfills(raw, modernTargets, polyfillsDiscovered.modern);
|
|
375
424
|
}
|
|
376
425
|
const ms = new MagicString__default(raw);
|
|
377
426
|
if (genLegacy && chunk.isEntry) {
|
|
@@ -420,7 +469,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
420
469
|
[
|
|
421
470
|
() => ({
|
|
422
471
|
plugins: [
|
|
423
|
-
recordAndRemovePolyfillBabelPlugin(
|
|
472
|
+
recordAndRemovePolyfillBabelPlugin(polyfillsDiscovered.legacy),
|
|
424
473
|
replaceLegacyEnvBabelPlugin(),
|
|
425
474
|
wrapIIFEBabelPlugin()
|
|
426
475
|
]
|
package/dist/index.d.cts
CHANGED
|
@@ -8,7 +8,7 @@ interface Options {
|
|
|
8
8
|
[key: string]: string;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* default: 'edge>=
|
|
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>=
|
|
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>=
|
|
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
|
@@ -11,17 +11,21 @@ function getDefaultExportFromCjs (x) {
|
|
|
11
11
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
function commonjsRequire(path) {
|
|
15
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
16
|
+
}
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
var picocolors = {exports: {}};
|
|
17
19
|
|
|
20
|
+
let argv = process.argv || [],
|
|
21
|
+
env = process.env;
|
|
18
22
|
let isColorSupported =
|
|
19
|
-
!("NO_COLOR" in
|
|
20
|
-
("FORCE_COLOR" in
|
|
21
|
-
|
|
23
|
+
!("NO_COLOR" in env || argv.includes("--no-color")) &&
|
|
24
|
+
("FORCE_COLOR" in env ||
|
|
25
|
+
argv.includes("--color") ||
|
|
22
26
|
process.platform === "win32" ||
|
|
23
|
-
(
|
|
24
|
-
"CI" in
|
|
27
|
+
(commonjsRequire != null && require$$0.isatty(1) && env.TERM !== "dumb") ||
|
|
28
|
+
"CI" in env);
|
|
25
29
|
|
|
26
30
|
let formatter =
|
|
27
31
|
(open, close, replace = open) =>
|
|
@@ -34,40 +38,47 @@ let formatter =
|
|
|
34
38
|
};
|
|
35
39
|
|
|
36
40
|
let replaceClose = (string, close, replace, index) => {
|
|
37
|
-
let
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
let result = "";
|
|
42
|
+
let cursor = 0;
|
|
43
|
+
do {
|
|
44
|
+
result += string.substring(cursor, index) + replace;
|
|
45
|
+
cursor = index + close.length;
|
|
46
|
+
index = string.indexOf(close, cursor);
|
|
47
|
+
} while (~index)
|
|
48
|
+
return result + string.substring(cursor)
|
|
41
49
|
};
|
|
42
50
|
|
|
43
|
-
let createColors = (enabled = isColorSupported) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
51
|
+
let createColors = (enabled = isColorSupported) => {
|
|
52
|
+
let init = enabled ? formatter : () => String;
|
|
53
|
+
return {
|
|
54
|
+
isColorSupported: enabled,
|
|
55
|
+
reset: init("\x1b[0m", "\x1b[0m"),
|
|
56
|
+
bold: init("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|
57
|
+
dim: init("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|
58
|
+
italic: init("\x1b[3m", "\x1b[23m"),
|
|
59
|
+
underline: init("\x1b[4m", "\x1b[24m"),
|
|
60
|
+
inverse: init("\x1b[7m", "\x1b[27m"),
|
|
61
|
+
hidden: init("\x1b[8m", "\x1b[28m"),
|
|
62
|
+
strikethrough: init("\x1b[9m", "\x1b[29m"),
|
|
63
|
+
black: init("\x1b[30m", "\x1b[39m"),
|
|
64
|
+
red: init("\x1b[31m", "\x1b[39m"),
|
|
65
|
+
green: init("\x1b[32m", "\x1b[39m"),
|
|
66
|
+
yellow: init("\x1b[33m", "\x1b[39m"),
|
|
67
|
+
blue: init("\x1b[34m", "\x1b[39m"),
|
|
68
|
+
magenta: init("\x1b[35m", "\x1b[39m"),
|
|
69
|
+
cyan: init("\x1b[36m", "\x1b[39m"),
|
|
70
|
+
white: init("\x1b[37m", "\x1b[39m"),
|
|
71
|
+
gray: init("\x1b[90m", "\x1b[39m"),
|
|
72
|
+
bgBlack: init("\x1b[40m", "\x1b[49m"),
|
|
73
|
+
bgRed: init("\x1b[41m", "\x1b[49m"),
|
|
74
|
+
bgGreen: init("\x1b[42m", "\x1b[49m"),
|
|
75
|
+
bgYellow: init("\x1b[43m", "\x1b[49m"),
|
|
76
|
+
bgBlue: init("\x1b[44m", "\x1b[49m"),
|
|
77
|
+
bgMagenta: init("\x1b[45m", "\x1b[49m"),
|
|
78
|
+
bgCyan: init("\x1b[46m", "\x1b[49m"),
|
|
79
|
+
bgWhite: init("\x1b[47m", "\x1b[49m"),
|
|
80
|
+
}
|
|
81
|
+
};
|
|
71
82
|
|
|
72
83
|
picocolors.exports = createColors();
|
|
73
84
|
picocolors.exports.createColors = createColors;
|
|
@@ -155,7 +166,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
155
166
|
"chrome64",
|
|
156
167
|
"safari12"
|
|
157
168
|
];
|
|
158
|
-
const modernTargetsBabel = "edge>=
|
|
169
|
+
const modernTargetsBabel = "edge>=79, firefox>=67, chrome>=64, safari>=12, chromeAndroid>=64, iOS>=12";
|
|
159
170
|
const genLegacy = options.renderLegacyChunks !== false;
|
|
160
171
|
const genModern = options.renderModernChunks !== false;
|
|
161
172
|
if (!genLegacy && !genModern) {
|
|
@@ -170,6 +181,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
170
181
|
const facadeToModernPolyfillMap = /* @__PURE__ */ new Map();
|
|
171
182
|
const modernPolyfills = /* @__PURE__ */ new Set();
|
|
172
183
|
const legacyPolyfills = /* @__PURE__ */ new Set();
|
|
184
|
+
const outputToChunkFileNameToPolyfills = /* @__PURE__ */ new WeakMap();
|
|
173
185
|
if (Array.isArray(options.modernPolyfills) && genModern) {
|
|
174
186
|
options.modernPolyfills.forEach((i) => {
|
|
175
187
|
modernPolyfills.add(
|
|
@@ -177,6 +189,11 @@ function viteLegacyPlugin(options = {}) {
|
|
|
177
189
|
);
|
|
178
190
|
});
|
|
179
191
|
}
|
|
192
|
+
if (Array.isArray(options.additionalModernPolyfills)) {
|
|
193
|
+
options.additionalModernPolyfills.forEach((i) => {
|
|
194
|
+
modernPolyfills.add(i);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
180
197
|
if (Array.isArray(options.polyfills)) {
|
|
181
198
|
options.polyfills.forEach((i) => {
|
|
182
199
|
if (i.startsWith(`regenerator`)) {
|
|
@@ -246,7 +263,16 @@ function viteLegacyPlugin(options = {}) {
|
|
|
246
263
|
if (config.build.ssr) {
|
|
247
264
|
return;
|
|
248
265
|
}
|
|
266
|
+
const chunkFileNameToPolyfills = outputToChunkFileNameToPolyfills.get(opts);
|
|
267
|
+
if (chunkFileNameToPolyfills == null) {
|
|
268
|
+
throw new Error(
|
|
269
|
+
"Internal @vitejs/plugin-legacy error: discovered polyfills should exist"
|
|
270
|
+
);
|
|
271
|
+
}
|
|
249
272
|
if (!isLegacyBundle(bundle, opts)) {
|
|
273
|
+
for (const { modern } of chunkFileNameToPolyfills.values()) {
|
|
274
|
+
modern.forEach((p) => modernPolyfills.add(p));
|
|
275
|
+
}
|
|
250
276
|
if (!modernPolyfills.size) {
|
|
251
277
|
return;
|
|
252
278
|
}
|
|
@@ -272,6 +298,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
272
298
|
if (!genLegacy) {
|
|
273
299
|
return;
|
|
274
300
|
}
|
|
301
|
+
for (const { legacy } of chunkFileNameToPolyfills.values()) {
|
|
302
|
+
legacy.forEach((p) => legacyPolyfills.add(p));
|
|
303
|
+
}
|
|
275
304
|
if (options.polyfills !== false) {
|
|
276
305
|
await detectPolyfills(
|
|
277
306
|
`Promise.resolve(); Promise.all();`,
|
|
@@ -303,6 +332,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
303
332
|
name: "vite:legacy-post-process",
|
|
304
333
|
enforce: "post",
|
|
305
334
|
apply: "build",
|
|
335
|
+
renderStart(opts) {
|
|
336
|
+
outputToChunkFileNameToPolyfills.set(opts, null);
|
|
337
|
+
},
|
|
306
338
|
configResolved(_config) {
|
|
307
339
|
if (_config.build.lib) {
|
|
308
340
|
throw new Error("@vitejs/plugin-legacy does not support library mode.");
|
|
@@ -353,13 +385,30 @@ function viteLegacyPlugin(options = {}) {
|
|
|
353
385
|
];
|
|
354
386
|
}
|
|
355
387
|
},
|
|
356
|
-
async renderChunk(raw, chunk, opts) {
|
|
388
|
+
async renderChunk(raw, chunk, opts, { chunks }) {
|
|
357
389
|
if (config.build.ssr) {
|
|
358
390
|
return null;
|
|
359
391
|
}
|
|
392
|
+
let chunkFileNameToPolyfills = outputToChunkFileNameToPolyfills.get(opts);
|
|
393
|
+
if (chunkFileNameToPolyfills == null) {
|
|
394
|
+
chunkFileNameToPolyfills = /* @__PURE__ */ new Map();
|
|
395
|
+
for (const fileName in chunks) {
|
|
396
|
+
chunkFileNameToPolyfills.set(fileName, {
|
|
397
|
+
modern: /* @__PURE__ */ new Set(),
|
|
398
|
+
legacy: /* @__PURE__ */ new Set()
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
outputToChunkFileNameToPolyfills.set(opts, chunkFileNameToPolyfills);
|
|
402
|
+
}
|
|
403
|
+
const polyfillsDiscovered = chunkFileNameToPolyfills.get(chunk.fileName);
|
|
404
|
+
if (polyfillsDiscovered == null) {
|
|
405
|
+
throw new Error(
|
|
406
|
+
`Internal @vitejs/plugin-legacy error: discovered polyfills for ${chunk.fileName} should exist`
|
|
407
|
+
);
|
|
408
|
+
}
|
|
360
409
|
if (!isLegacyChunk(chunk, opts)) {
|
|
361
410
|
if (options.modernPolyfills && !Array.isArray(options.modernPolyfills) && genModern) {
|
|
362
|
-
await detectPolyfills(raw, modernTargets,
|
|
411
|
+
await detectPolyfills(raw, modernTargets, polyfillsDiscovered.modern);
|
|
363
412
|
}
|
|
364
413
|
const ms = new MagicString(raw);
|
|
365
414
|
if (genLegacy && chunk.isEntry) {
|
|
@@ -408,7 +457,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
408
457
|
[
|
|
409
458
|
() => ({
|
|
410
459
|
plugins: [
|
|
411
|
-
recordAndRemovePolyfillBabelPlugin(
|
|
460
|
+
recordAndRemovePolyfillBabelPlugin(polyfillsDiscovered.legacy),
|
|
412
461
|
replaceLegacyEnvBabelPlugin(),
|
|
413
462
|
wrapIIFEBabelPlugin()
|
|
414
463
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-legacy",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.1",
|
|
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.
|
|
39
|
-
"@babel/preset-env": "^7.
|
|
38
|
+
"@babel/core": "^7.24.6",
|
|
39
|
+
"@babel/preset-env": "^7.24.6",
|
|
40
40
|
"browserslist": "^4.23.0",
|
|
41
41
|
"browserslist-to-esbuild": "^2.1.1",
|
|
42
|
-
"core-js": "^3.
|
|
43
|
-
"magic-string": "^0.30.
|
|
42
|
+
"core-js": "^3.37.1",
|
|
43
|
+
"magic-string": "^0.30.10",
|
|
44
44
|
"regenerator-runtime": "^0.14.1",
|
|
45
|
-
"systemjs": "^6.
|
|
45
|
+
"systemjs": "^6.15.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"terser": "^5.4.0",
|
|
@@ -50,8 +50,9 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"acorn": "^8.11.3",
|
|
53
|
-
"picocolors": "^1.0.
|
|
54
|
-
"
|
|
53
|
+
"picocolors": "^1.0.1",
|
|
54
|
+
"unbuild": "^2.0.0",
|
|
55
|
+
"vite": "5.2.12"
|
|
55
56
|
},
|
|
56
57
|
"scripts": {
|
|
57
58
|
"dev": "unbuild --stub",
|