@vitejs/plugin-legacy 6.0.1 → 6.1.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/dist/index.cjs +25 -8
- package/dist/index.d.cts +9 -2
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.mjs +25 -8
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -164,7 +164,7 @@ function joinUrlSegments(a, b) {
|
|
|
164
164
|
if (!a || !b) {
|
|
165
165
|
return a || b || "";
|
|
166
166
|
}
|
|
167
|
-
if (a
|
|
167
|
+
if (a.endsWith("/")) {
|
|
168
168
|
a = a.substring(0, a.length - 1);
|
|
169
169
|
}
|
|
170
170
|
if (b[0] !== "/") {
|
|
@@ -209,6 +209,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
209
209
|
}
|
|
210
210
|
const debugFlags = (process.env.DEBUG || "").split(",");
|
|
211
211
|
const isDebug = debugFlags.includes("vite:*") || debugFlags.includes("vite:legacy");
|
|
212
|
+
const assumptions = options.assumptions || {};
|
|
212
213
|
const facadeToLegacyChunkMap = /* @__PURE__ */ new Map();
|
|
213
214
|
const facadeToLegacyPolyfillMap = /* @__PURE__ */ new Map();
|
|
214
215
|
const facadeToModernPolyfillMap = /* @__PURE__ */ new Map();
|
|
@@ -256,8 +257,8 @@ function viteLegacyPlugin(options = {}) {
|
|
|
256
257
|
config2.build.cssTarget = "chrome61";
|
|
257
258
|
}
|
|
258
259
|
if (genLegacy) {
|
|
259
|
-
overriddenBuildTarget = config2.build.target !==
|
|
260
|
-
overriddenDefaultModernTargets = options.modernTargets !==
|
|
260
|
+
overriddenBuildTarget = config2.build.target !== void 0;
|
|
261
|
+
overriddenDefaultModernTargets = options.modernTargets !== void 0;
|
|
261
262
|
if (options.modernTargets) {
|
|
262
263
|
const { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');
|
|
263
264
|
config2.build.target = browserslistToEsbuild(options.modernTargets);
|
|
@@ -287,6 +288,13 @@ function viteLegacyPlugin(options = {}) {
|
|
|
287
288
|
)
|
|
288
289
|
);
|
|
289
290
|
}
|
|
291
|
+
if (config2.isWorker) {
|
|
292
|
+
config2.logger.warn(
|
|
293
|
+
colors.yellow(
|
|
294
|
+
`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.`
|
|
295
|
+
)
|
|
296
|
+
);
|
|
297
|
+
}
|
|
290
298
|
}
|
|
291
299
|
};
|
|
292
300
|
const legacyGenerateBundlePlugin = {
|
|
@@ -338,6 +346,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
338
346
|
await detectPolyfills(
|
|
339
347
|
`Promise.resolve(); Promise.all();`,
|
|
340
348
|
targets,
|
|
349
|
+
assumptions,
|
|
341
350
|
legacyPolyfills
|
|
342
351
|
);
|
|
343
352
|
}
|
|
@@ -447,7 +456,12 @@ function viteLegacyPlugin(options = {}) {
|
|
|
447
456
|
}
|
|
448
457
|
if (!isLegacyChunk(chunk, opts)) {
|
|
449
458
|
if (options.modernPolyfills && !Array.isArray(options.modernPolyfills) && genModern) {
|
|
450
|
-
await detectPolyfills(
|
|
459
|
+
await detectPolyfills(
|
|
460
|
+
raw,
|
|
461
|
+
modernTargets,
|
|
462
|
+
assumptions,
|
|
463
|
+
polyfillsDiscovered.modern
|
|
464
|
+
);
|
|
451
465
|
}
|
|
452
466
|
const ms = new MagicString__default(raw);
|
|
453
467
|
if (genLegacy && chunk.isEntry) {
|
|
@@ -488,7 +502,8 @@ function viteLegacyPlugin(options = {}) {
|
|
|
488
502
|
configFile: false,
|
|
489
503
|
compact: !!config.build.minify,
|
|
490
504
|
sourceMaps,
|
|
491
|
-
inputSourceMap:
|
|
505
|
+
inputSourceMap: void 0,
|
|
506
|
+
assumptions,
|
|
492
507
|
presets: [
|
|
493
508
|
// forcing our plugin to run before preset-env by wrapping it in a
|
|
494
509
|
// preset so we can catch the injected import statements...
|
|
@@ -642,13 +657,14 @@ function viteLegacyPlugin(options = {}) {
|
|
|
642
657
|
};
|
|
643
658
|
return [legacyConfigPlugin, legacyGenerateBundlePlugin, legacyPostPlugin];
|
|
644
659
|
}
|
|
645
|
-
async function detectPolyfills(code, targets, list) {
|
|
660
|
+
async function detectPolyfills(code, targets, assumptions, list) {
|
|
646
661
|
const babel2 = await loadBabel();
|
|
647
662
|
const result = babel2.transform(code, {
|
|
648
663
|
ast: true,
|
|
649
664
|
babelrc: false,
|
|
650
665
|
configFile: false,
|
|
651
666
|
compact: false,
|
|
667
|
+
assumptions,
|
|
652
668
|
presets: [
|
|
653
669
|
[
|
|
654
670
|
(await import('@babel/preset-env')).default,
|
|
@@ -675,7 +691,7 @@ function createBabelPresetEnvOptions(targets, { needPolyfills = true }) {
|
|
|
675
691
|
corejs: needPolyfills ? {
|
|
676
692
|
version: _require("core-js/package.json").version,
|
|
677
693
|
proposals: false
|
|
678
|
-
} :
|
|
694
|
+
} : void 0,
|
|
679
695
|
shippedProposals: true,
|
|
680
696
|
ignoreBrowserslistConfig: true
|
|
681
697
|
};
|
|
@@ -705,7 +721,8 @@ async function buildPolyfillChunk(mode, imports, bundle, facadeToChunkMap, build
|
|
|
705
721
|
output: {
|
|
706
722
|
format,
|
|
707
723
|
hashCharacters: rollupOutputOptions.hashCharacters,
|
|
708
|
-
entryFileNames: rollupOutputOptions.entryFileNames
|
|
724
|
+
entryFileNames: rollupOutputOptions.entryFileNames,
|
|
725
|
+
sourcemapBaseUrl: rollupOutputOptions.sourcemapBaseUrl
|
|
709
726
|
}
|
|
710
727
|
}
|
|
711
728
|
},
|
package/dist/index.d.cts
CHANGED
|
@@ -31,10 +31,17 @@ interface Options {
|
|
|
31
31
|
* default: true
|
|
32
32
|
*/
|
|
33
33
|
renderModernChunks?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @see https://babeljs.io/docs/assumptions
|
|
36
|
+
*
|
|
37
|
+
* default: {}
|
|
38
|
+
*/
|
|
39
|
+
assumptions?: Record<string, boolean>;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
declare function viteLegacyPlugin(options?: Options): Plugin[];
|
|
37
|
-
declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
|
|
43
|
+
declare function detectPolyfills(code: string, targets: any, assumptions: Record<string, boolean>, list: Set<string>): Promise<void>;
|
|
38
44
|
declare const cspHashes: string[];
|
|
39
45
|
|
|
40
|
-
export
|
|
46
|
+
export = viteLegacyPlugin;
|
|
47
|
+
export { type Options, cspHashes, detectPolyfills };
|
package/dist/index.d.mts
CHANGED
|
@@ -31,10 +31,16 @@ interface Options {
|
|
|
31
31
|
* default: true
|
|
32
32
|
*/
|
|
33
33
|
renderModernChunks?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @see https://babeljs.io/docs/assumptions
|
|
36
|
+
*
|
|
37
|
+
* default: {}
|
|
38
|
+
*/
|
|
39
|
+
assumptions?: Record<string, boolean>;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
declare function viteLegacyPlugin(options?: Options): Plugin[];
|
|
37
|
-
declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
|
|
43
|
+
declare function detectPolyfills(code: string, targets: any, assumptions: Record<string, boolean>, list: Set<string>): Promise<void>;
|
|
38
44
|
declare const cspHashes: string[];
|
|
39
45
|
|
|
40
46
|
export { type Options, cspHashes, viteLegacyPlugin as default, detectPolyfills };
|
package/dist/index.d.ts
CHANGED
|
@@ -31,10 +31,17 @@ interface Options {
|
|
|
31
31
|
* default: true
|
|
32
32
|
*/
|
|
33
33
|
renderModernChunks?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @see https://babeljs.io/docs/assumptions
|
|
36
|
+
*
|
|
37
|
+
* default: {}
|
|
38
|
+
*/
|
|
39
|
+
assumptions?: Record<string, boolean>;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
declare function viteLegacyPlugin(options?: Options): Plugin[];
|
|
37
|
-
declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
|
|
43
|
+
declare function detectPolyfills(code: string, targets: any, assumptions: Record<string, boolean>, list: Set<string>): Promise<void>;
|
|
38
44
|
declare const cspHashes: string[];
|
|
39
45
|
|
|
40
|
-
export
|
|
46
|
+
export = viteLegacyPlugin;
|
|
47
|
+
export { type Options, cspHashes, detectPolyfills };
|
package/dist/index.mjs
CHANGED
|
@@ -152,7 +152,7 @@ function joinUrlSegments(a, b) {
|
|
|
152
152
|
if (!a || !b) {
|
|
153
153
|
return a || b || "";
|
|
154
154
|
}
|
|
155
|
-
if (a
|
|
155
|
+
if (a.endsWith("/")) {
|
|
156
156
|
a = a.substring(0, a.length - 1);
|
|
157
157
|
}
|
|
158
158
|
if (b[0] !== "/") {
|
|
@@ -197,6 +197,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
197
197
|
}
|
|
198
198
|
const debugFlags = (process.env.DEBUG || "").split(",");
|
|
199
199
|
const isDebug = debugFlags.includes("vite:*") || debugFlags.includes("vite:legacy");
|
|
200
|
+
const assumptions = options.assumptions || {};
|
|
200
201
|
const facadeToLegacyChunkMap = /* @__PURE__ */ new Map();
|
|
201
202
|
const facadeToLegacyPolyfillMap = /* @__PURE__ */ new Map();
|
|
202
203
|
const facadeToModernPolyfillMap = /* @__PURE__ */ new Map();
|
|
@@ -244,8 +245,8 @@ function viteLegacyPlugin(options = {}) {
|
|
|
244
245
|
config2.build.cssTarget = "chrome61";
|
|
245
246
|
}
|
|
246
247
|
if (genLegacy) {
|
|
247
|
-
overriddenBuildTarget = config2.build.target !==
|
|
248
|
-
overriddenDefaultModernTargets = options.modernTargets !==
|
|
248
|
+
overriddenBuildTarget = config2.build.target !== void 0;
|
|
249
|
+
overriddenDefaultModernTargets = options.modernTargets !== void 0;
|
|
249
250
|
if (options.modernTargets) {
|
|
250
251
|
const { default: browserslistToEsbuild } = await import('browserslist-to-esbuild');
|
|
251
252
|
config2.build.target = browserslistToEsbuild(options.modernTargets);
|
|
@@ -275,6 +276,13 @@ function viteLegacyPlugin(options = {}) {
|
|
|
275
276
|
)
|
|
276
277
|
);
|
|
277
278
|
}
|
|
279
|
+
if (config2.isWorker) {
|
|
280
|
+
config2.logger.warn(
|
|
281
|
+
colors.yellow(
|
|
282
|
+
`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.`
|
|
283
|
+
)
|
|
284
|
+
);
|
|
285
|
+
}
|
|
278
286
|
}
|
|
279
287
|
};
|
|
280
288
|
const legacyGenerateBundlePlugin = {
|
|
@@ -326,6 +334,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
326
334
|
await detectPolyfills(
|
|
327
335
|
`Promise.resolve(); Promise.all();`,
|
|
328
336
|
targets,
|
|
337
|
+
assumptions,
|
|
329
338
|
legacyPolyfills
|
|
330
339
|
);
|
|
331
340
|
}
|
|
@@ -435,7 +444,12 @@ function viteLegacyPlugin(options = {}) {
|
|
|
435
444
|
}
|
|
436
445
|
if (!isLegacyChunk(chunk, opts)) {
|
|
437
446
|
if (options.modernPolyfills && !Array.isArray(options.modernPolyfills) && genModern) {
|
|
438
|
-
await detectPolyfills(
|
|
447
|
+
await detectPolyfills(
|
|
448
|
+
raw,
|
|
449
|
+
modernTargets,
|
|
450
|
+
assumptions,
|
|
451
|
+
polyfillsDiscovered.modern
|
|
452
|
+
);
|
|
439
453
|
}
|
|
440
454
|
const ms = new MagicString(raw);
|
|
441
455
|
if (genLegacy && chunk.isEntry) {
|
|
@@ -476,7 +490,8 @@ function viteLegacyPlugin(options = {}) {
|
|
|
476
490
|
configFile: false,
|
|
477
491
|
compact: !!config.build.minify,
|
|
478
492
|
sourceMaps,
|
|
479
|
-
inputSourceMap:
|
|
493
|
+
inputSourceMap: void 0,
|
|
494
|
+
assumptions,
|
|
480
495
|
presets: [
|
|
481
496
|
// forcing our plugin to run before preset-env by wrapping it in a
|
|
482
497
|
// preset so we can catch the injected import statements...
|
|
@@ -630,13 +645,14 @@ function viteLegacyPlugin(options = {}) {
|
|
|
630
645
|
};
|
|
631
646
|
return [legacyConfigPlugin, legacyGenerateBundlePlugin, legacyPostPlugin];
|
|
632
647
|
}
|
|
633
|
-
async function detectPolyfills(code, targets, list) {
|
|
648
|
+
async function detectPolyfills(code, targets, assumptions, list) {
|
|
634
649
|
const babel2 = await loadBabel();
|
|
635
650
|
const result = babel2.transform(code, {
|
|
636
651
|
ast: true,
|
|
637
652
|
babelrc: false,
|
|
638
653
|
configFile: false,
|
|
639
654
|
compact: false,
|
|
655
|
+
assumptions,
|
|
640
656
|
presets: [
|
|
641
657
|
[
|
|
642
658
|
(await import('@babel/preset-env')).default,
|
|
@@ -663,7 +679,7 @@ function createBabelPresetEnvOptions(targets, { needPolyfills = true }) {
|
|
|
663
679
|
corejs: needPolyfills ? {
|
|
664
680
|
version: _require("core-js/package.json").version,
|
|
665
681
|
proposals: false
|
|
666
|
-
} :
|
|
682
|
+
} : void 0,
|
|
667
683
|
shippedProposals: true,
|
|
668
684
|
ignoreBrowserslistConfig: true
|
|
669
685
|
};
|
|
@@ -693,7 +709,8 @@ async function buildPolyfillChunk(mode, imports, bundle, facadeToChunkMap, build
|
|
|
693
709
|
output: {
|
|
694
710
|
format,
|
|
695
711
|
hashCharacters: rollupOutputOptions.hashCharacters,
|
|
696
|
-
entryFileNames: rollupOutputOptions.entryFileNames
|
|
712
|
+
entryFileNames: rollupOutputOptions.entryFileNames,
|
|
713
|
+
sourcemapBaseUrl: rollupOutputOptions.sourcemapBaseUrl
|
|
697
714
|
}
|
|
698
715
|
}
|
|
699
716
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-legacy",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Evan You",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
|
|
37
37
|
"funding": "https://github.com/vitejs/vite?sponsor=1",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@babel/core": "^7.26.
|
|
40
|
-
"@babel/preset-env": "^7.26.
|
|
39
|
+
"@babel/core": "^7.26.10",
|
|
40
|
+
"@babel/preset-env": "^7.26.9",
|
|
41
41
|
"browserslist": "^4.24.4",
|
|
42
42
|
"browserslist-to-esbuild": "^2.1.1",
|
|
43
|
-
"core-js": "^3.
|
|
43
|
+
"core-js": "^3.41.0",
|
|
44
44
|
"magic-string": "^0.30.17",
|
|
45
45
|
"regenerator-runtime": "^0.14.1",
|
|
46
46
|
"systemjs": "^6.15.1"
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"vite": "^6.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"acorn": "^8.14.
|
|
53
|
+
"acorn": "^8.14.1",
|
|
54
54
|
"picocolors": "^1.1.1",
|
|
55
|
-
"unbuild": "^3.
|
|
56
|
-
"vite": "6.
|
|
55
|
+
"unbuild": "^3.5.0",
|
|
56
|
+
"vite": "6.3.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"dev": "unbuild --stub",
|