@vitejs/plugin-legacy 5.0.0-beta.0 → 5.0.0-beta.2
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 +2 -12
- package/dist/index.cjs +25 -22
- package/dist/index.d.cts +37 -0
- package/dist/index.d.mts +37 -0
- package/dist/index.d.ts +0 -4
- package/dist/index.mjs +25 -22
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -44,6 +44,8 @@ npm add -D terser
|
|
|
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
|
|
|
47
|
+
If it's not set, plugin-legacy will load [the browserslist config sources](https://github.com/browserslist/browserslist#queries) and then fallback to the default value.
|
|
48
|
+
|
|
47
49
|
### `polyfills`
|
|
48
50
|
|
|
49
51
|
- **Type:** `boolean | string[]`
|
|
@@ -63,18 +65,6 @@ npm add -D terser
|
|
|
63
65
|
|
|
64
66
|
Note: if additional polyfills are needed for both the modern and legacy chunks, they can simply be imported in the application source code.
|
|
65
67
|
|
|
66
|
-
### `ignoreBrowserslistConfig`
|
|
67
|
-
|
|
68
|
-
- **Type:** `boolean`
|
|
69
|
-
- **Default:** `false`
|
|
70
|
-
|
|
71
|
-
`@babel/preset-env` automatically detects [`browserslist` config sources](https://github.com/browserslist/browserslist#browserslist-):
|
|
72
|
-
|
|
73
|
-
- `browserslist` field in `package.json`
|
|
74
|
-
- `.browserslistrc` file in cwd.
|
|
75
|
-
|
|
76
|
-
Set to `true` to ignore these sources.
|
|
77
|
-
|
|
78
68
|
### `modernPolyfills`
|
|
79
69
|
|
|
80
70
|
- **Type:** `boolean | string[]`
|
package/dist/index.cjs
CHANGED
|
@@ -157,6 +157,14 @@ const _require = node_module.createRequire((typeof document === 'undefined' ? re
|
|
|
157
157
|
function viteLegacyPlugin(options = {}) {
|
|
158
158
|
let config;
|
|
159
159
|
let targets;
|
|
160
|
+
const modernTargetsEsbuild = [
|
|
161
|
+
"es2020",
|
|
162
|
+
"edge79",
|
|
163
|
+
"firefox67",
|
|
164
|
+
"chrome64",
|
|
165
|
+
"safari12"
|
|
166
|
+
];
|
|
167
|
+
const modernTargetsBabel = "edge>=80, firefox>=72, chrome>=80, safari>=13.1, chromeAndroid>=80, iOS>=13.1";
|
|
160
168
|
const genLegacy = options.renderLegacyChunks !== false;
|
|
161
169
|
const genModern = options.renderModernChunks !== false;
|
|
162
170
|
if (!genLegacy && !genModern) {
|
|
@@ -207,13 +215,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
207
215
|
}
|
|
208
216
|
if (genLegacy) {
|
|
209
217
|
overriddenBuildTarget = config2.build.target !== void 0;
|
|
210
|
-
config2.build.target =
|
|
211
|
-
"es2020",
|
|
212
|
-
"edge79",
|
|
213
|
-
"firefox67",
|
|
214
|
-
"chrome64",
|
|
215
|
-
"safari12"
|
|
216
|
-
];
|
|
218
|
+
config2.build.target = modernTargetsEsbuild;
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
221
|
return {
|
|
@@ -247,7 +249,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
247
249
|
`[@vitejs/plugin-legacy] modern polyfills:`,
|
|
248
250
|
modernPolyfills
|
|
249
251
|
);
|
|
250
|
-
await buildPolyfillChunk(
|
|
252
|
+
const polyfillChunk = await buildPolyfillChunk(
|
|
251
253
|
config.mode,
|
|
252
254
|
modernPolyfills,
|
|
253
255
|
bundle,
|
|
@@ -257,17 +259,22 @@ function viteLegacyPlugin(options = {}) {
|
|
|
257
259
|
opts,
|
|
258
260
|
true
|
|
259
261
|
);
|
|
262
|
+
if (genLegacy && polyfillChunk) {
|
|
263
|
+
polyfillChunk.code = modernChunkLegacyGuard + polyfillChunk.code;
|
|
264
|
+
}
|
|
260
265
|
return;
|
|
261
266
|
}
|
|
262
267
|
if (!genLegacy) {
|
|
263
268
|
return;
|
|
264
269
|
}
|
|
265
|
-
if (
|
|
270
|
+
if (options.polyfills !== false) {
|
|
266
271
|
await detectPolyfills(
|
|
267
272
|
`Promise.resolve(); Promise.all();`,
|
|
268
273
|
targets,
|
|
269
274
|
legacyPolyfills
|
|
270
275
|
);
|
|
276
|
+
}
|
|
277
|
+
if (legacyPolyfills.size || !options.externalSystemJS) {
|
|
271
278
|
isDebug && console.log(
|
|
272
279
|
`[@vitejs/plugin-legacy] legacy polyfills:`,
|
|
273
280
|
legacyPolyfills
|
|
@@ -309,6 +316,8 @@ function viteLegacyPlugin(options = {}) {
|
|
|
309
316
|
let fileName = typeof fileNames === "function" ? fileNames(chunkInfo) : fileNames;
|
|
310
317
|
if (fileName.includes("[name]")) {
|
|
311
318
|
fileName = fileName.replace("[name]", "[name]-legacy");
|
|
319
|
+
} else if (fileName.includes("[hash]")) {
|
|
320
|
+
fileName = fileName.replace(/[.-]?\[hash\]/, "-legacy$&");
|
|
312
321
|
} else {
|
|
313
322
|
fileName = fileName.replace(/(.+)\.(.+)/, "$1-legacy.$2");
|
|
314
323
|
}
|
|
@@ -343,7 +352,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
343
352
|
}
|
|
344
353
|
if (!isLegacyChunk(chunk, opts)) {
|
|
345
354
|
if (options.modernPolyfills && !Array.isArray(options.modernPolyfills) && genModern) {
|
|
346
|
-
await detectPolyfills(raw,
|
|
355
|
+
await detectPolyfills(raw, modernTargetsBabel, modernPolyfills);
|
|
347
356
|
}
|
|
348
357
|
const ms = new MagicString__default(raw);
|
|
349
358
|
if (genLegacy && chunk.isEntry) {
|
|
@@ -400,10 +409,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
400
409
|
],
|
|
401
410
|
[
|
|
402
411
|
(await import('@babel/preset-env')).default,
|
|
403
|
-
createBabelPresetEnvOptions(targets, {
|
|
404
|
-
needPolyfills,
|
|
405
|
-
ignoreBrowserslistConfig: options.ignoreBrowserslistConfig
|
|
406
|
-
})
|
|
412
|
+
createBabelPresetEnvOptions(targets, { needPolyfills })
|
|
407
413
|
]
|
|
408
414
|
]
|
|
409
415
|
});
|
|
@@ -551,12 +557,11 @@ async function detectPolyfills(code, targets, list) {
|
|
|
551
557
|
ast: true,
|
|
552
558
|
babelrc: false,
|
|
553
559
|
configFile: false,
|
|
560
|
+
compact: false,
|
|
554
561
|
presets: [
|
|
555
562
|
[
|
|
556
563
|
(await import('@babel/preset-env')).default,
|
|
557
|
-
createBabelPresetEnvOptions(targets, {
|
|
558
|
-
ignoreBrowserslistConfig: true
|
|
559
|
-
})
|
|
564
|
+
createBabelPresetEnvOptions(targets, {})
|
|
560
565
|
]
|
|
561
566
|
]
|
|
562
567
|
});
|
|
@@ -569,10 +574,7 @@ async function detectPolyfills(code, targets, list) {
|
|
|
569
574
|
}
|
|
570
575
|
}
|
|
571
576
|
}
|
|
572
|
-
function createBabelPresetEnvOptions(targets, {
|
|
573
|
-
needPolyfills = true,
|
|
574
|
-
ignoreBrowserslistConfig
|
|
575
|
-
}) {
|
|
577
|
+
function createBabelPresetEnvOptions(targets, { needPolyfills = true }) {
|
|
576
578
|
return {
|
|
577
579
|
targets,
|
|
578
580
|
bugfixes: true,
|
|
@@ -584,7 +586,7 @@ function createBabelPresetEnvOptions(targets, {
|
|
|
584
586
|
proposals: false
|
|
585
587
|
} : void 0,
|
|
586
588
|
shippedProposals: true,
|
|
587
|
-
ignoreBrowserslistConfig
|
|
589
|
+
ignoreBrowserslistConfig: true
|
|
588
590
|
};
|
|
589
591
|
}
|
|
590
592
|
async function buildPolyfillChunk(mode, imports, bundle, facadeToChunkMap, buildOptions, format, rollupOutputOptions, excludeSystemJS) {
|
|
@@ -635,6 +637,7 @@ async function buildPolyfillChunk(mode, imports, bundle, facadeToChunkMap, build
|
|
|
635
637
|
}
|
|
636
638
|
}
|
|
637
639
|
bundle[polyfillChunk.fileName] = polyfillChunk;
|
|
640
|
+
return polyfillChunk;
|
|
638
641
|
}
|
|
639
642
|
const polyfillId = "\0vite/legacy-polyfills";
|
|
640
643
|
function polyfillsPlugin(imports, excludeSystemJS) {
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface Options {
|
|
4
|
+
/**
|
|
5
|
+
* default: 'defaults'
|
|
6
|
+
*/
|
|
7
|
+
targets?: string | string[] | {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* default: true
|
|
12
|
+
*/
|
|
13
|
+
polyfills?: boolean | string[];
|
|
14
|
+
additionalLegacyPolyfills?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* default: false
|
|
17
|
+
*/
|
|
18
|
+
modernPolyfills?: boolean | string[];
|
|
19
|
+
/**
|
|
20
|
+
* default: true
|
|
21
|
+
*/
|
|
22
|
+
renderLegacyChunks?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* default: false
|
|
25
|
+
*/
|
|
26
|
+
externalSystemJS?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* default: true
|
|
29
|
+
*/
|
|
30
|
+
renderModernChunks?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare function viteLegacyPlugin(options?: Options): Plugin[];
|
|
34
|
+
declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
|
|
35
|
+
declare const cspHashes: string[];
|
|
36
|
+
|
|
37
|
+
export { cspHashes, viteLegacyPlugin as default, detectPolyfills };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface Options {
|
|
4
|
+
/**
|
|
5
|
+
* default: 'defaults'
|
|
6
|
+
*/
|
|
7
|
+
targets?: string | string[] | {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* default: true
|
|
12
|
+
*/
|
|
13
|
+
polyfills?: boolean | string[];
|
|
14
|
+
additionalLegacyPolyfills?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* default: false
|
|
17
|
+
*/
|
|
18
|
+
modernPolyfills?: boolean | string[];
|
|
19
|
+
/**
|
|
20
|
+
* default: true
|
|
21
|
+
*/
|
|
22
|
+
renderLegacyChunks?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* default: false
|
|
25
|
+
*/
|
|
26
|
+
externalSystemJS?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* default: true
|
|
29
|
+
*/
|
|
30
|
+
renderModernChunks?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare function viteLegacyPlugin(options?: Options): Plugin[];
|
|
34
|
+
declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
|
|
35
|
+
declare const cspHashes: string[];
|
|
36
|
+
|
|
37
|
+
export { cspHashes, viteLegacyPlugin as default, detectPolyfills };
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -145,6 +145,14 @@ const _require = createRequire(import.meta.url);
|
|
|
145
145
|
function viteLegacyPlugin(options = {}) {
|
|
146
146
|
let config;
|
|
147
147
|
let targets;
|
|
148
|
+
const modernTargetsEsbuild = [
|
|
149
|
+
"es2020",
|
|
150
|
+
"edge79",
|
|
151
|
+
"firefox67",
|
|
152
|
+
"chrome64",
|
|
153
|
+
"safari12"
|
|
154
|
+
];
|
|
155
|
+
const modernTargetsBabel = "edge>=80, firefox>=72, chrome>=80, safari>=13.1, chromeAndroid>=80, iOS>=13.1";
|
|
148
156
|
const genLegacy = options.renderLegacyChunks !== false;
|
|
149
157
|
const genModern = options.renderModernChunks !== false;
|
|
150
158
|
if (!genLegacy && !genModern) {
|
|
@@ -195,13 +203,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
195
203
|
}
|
|
196
204
|
if (genLegacy) {
|
|
197
205
|
overriddenBuildTarget = config2.build.target !== void 0;
|
|
198
|
-
config2.build.target =
|
|
199
|
-
"es2020",
|
|
200
|
-
"edge79",
|
|
201
|
-
"firefox67",
|
|
202
|
-
"chrome64",
|
|
203
|
-
"safari12"
|
|
204
|
-
];
|
|
206
|
+
config2.build.target = modernTargetsEsbuild;
|
|
205
207
|
}
|
|
206
208
|
}
|
|
207
209
|
return {
|
|
@@ -235,7 +237,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
235
237
|
`[@vitejs/plugin-legacy] modern polyfills:`,
|
|
236
238
|
modernPolyfills
|
|
237
239
|
);
|
|
238
|
-
await buildPolyfillChunk(
|
|
240
|
+
const polyfillChunk = await buildPolyfillChunk(
|
|
239
241
|
config.mode,
|
|
240
242
|
modernPolyfills,
|
|
241
243
|
bundle,
|
|
@@ -245,17 +247,22 @@ function viteLegacyPlugin(options = {}) {
|
|
|
245
247
|
opts,
|
|
246
248
|
true
|
|
247
249
|
);
|
|
250
|
+
if (genLegacy && polyfillChunk) {
|
|
251
|
+
polyfillChunk.code = modernChunkLegacyGuard + polyfillChunk.code;
|
|
252
|
+
}
|
|
248
253
|
return;
|
|
249
254
|
}
|
|
250
255
|
if (!genLegacy) {
|
|
251
256
|
return;
|
|
252
257
|
}
|
|
253
|
-
if (
|
|
258
|
+
if (options.polyfills !== false) {
|
|
254
259
|
await detectPolyfills(
|
|
255
260
|
`Promise.resolve(); Promise.all();`,
|
|
256
261
|
targets,
|
|
257
262
|
legacyPolyfills
|
|
258
263
|
);
|
|
264
|
+
}
|
|
265
|
+
if (legacyPolyfills.size || !options.externalSystemJS) {
|
|
259
266
|
isDebug && console.log(
|
|
260
267
|
`[@vitejs/plugin-legacy] legacy polyfills:`,
|
|
261
268
|
legacyPolyfills
|
|
@@ -297,6 +304,8 @@ function viteLegacyPlugin(options = {}) {
|
|
|
297
304
|
let fileName = typeof fileNames === "function" ? fileNames(chunkInfo) : fileNames;
|
|
298
305
|
if (fileName.includes("[name]")) {
|
|
299
306
|
fileName = fileName.replace("[name]", "[name]-legacy");
|
|
307
|
+
} else if (fileName.includes("[hash]")) {
|
|
308
|
+
fileName = fileName.replace(/[.-]?\[hash\]/, "-legacy$&");
|
|
300
309
|
} else {
|
|
301
310
|
fileName = fileName.replace(/(.+)\.(.+)/, "$1-legacy.$2");
|
|
302
311
|
}
|
|
@@ -331,7 +340,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
331
340
|
}
|
|
332
341
|
if (!isLegacyChunk(chunk, opts)) {
|
|
333
342
|
if (options.modernPolyfills && !Array.isArray(options.modernPolyfills) && genModern) {
|
|
334
|
-
await detectPolyfills(raw,
|
|
343
|
+
await detectPolyfills(raw, modernTargetsBabel, modernPolyfills);
|
|
335
344
|
}
|
|
336
345
|
const ms = new MagicString(raw);
|
|
337
346
|
if (genLegacy && chunk.isEntry) {
|
|
@@ -388,10 +397,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
388
397
|
],
|
|
389
398
|
[
|
|
390
399
|
(await import('@babel/preset-env')).default,
|
|
391
|
-
createBabelPresetEnvOptions(targets, {
|
|
392
|
-
needPolyfills,
|
|
393
|
-
ignoreBrowserslistConfig: options.ignoreBrowserslistConfig
|
|
394
|
-
})
|
|
400
|
+
createBabelPresetEnvOptions(targets, { needPolyfills })
|
|
395
401
|
]
|
|
396
402
|
]
|
|
397
403
|
});
|
|
@@ -539,12 +545,11 @@ async function detectPolyfills(code, targets, list) {
|
|
|
539
545
|
ast: true,
|
|
540
546
|
babelrc: false,
|
|
541
547
|
configFile: false,
|
|
548
|
+
compact: false,
|
|
542
549
|
presets: [
|
|
543
550
|
[
|
|
544
551
|
(await import('@babel/preset-env')).default,
|
|
545
|
-
createBabelPresetEnvOptions(targets, {
|
|
546
|
-
ignoreBrowserslistConfig: true
|
|
547
|
-
})
|
|
552
|
+
createBabelPresetEnvOptions(targets, {})
|
|
548
553
|
]
|
|
549
554
|
]
|
|
550
555
|
});
|
|
@@ -557,10 +562,7 @@ async function detectPolyfills(code, targets, list) {
|
|
|
557
562
|
}
|
|
558
563
|
}
|
|
559
564
|
}
|
|
560
|
-
function createBabelPresetEnvOptions(targets, {
|
|
561
|
-
needPolyfills = true,
|
|
562
|
-
ignoreBrowserslistConfig
|
|
563
|
-
}) {
|
|
565
|
+
function createBabelPresetEnvOptions(targets, { needPolyfills = true }) {
|
|
564
566
|
return {
|
|
565
567
|
targets,
|
|
566
568
|
bugfixes: true,
|
|
@@ -572,7 +574,7 @@ function createBabelPresetEnvOptions(targets, {
|
|
|
572
574
|
proposals: false
|
|
573
575
|
} : void 0,
|
|
574
576
|
shippedProposals: true,
|
|
575
|
-
ignoreBrowserslistConfig
|
|
577
|
+
ignoreBrowserslistConfig: true
|
|
576
578
|
};
|
|
577
579
|
}
|
|
578
580
|
async function buildPolyfillChunk(mode, imports, bundle, facadeToChunkMap, buildOptions, format, rollupOutputOptions, excludeSystemJS) {
|
|
@@ -623,6 +625,7 @@ async function buildPolyfillChunk(mode, imports, bundle, facadeToChunkMap, build
|
|
|
623
625
|
}
|
|
624
626
|
}
|
|
625
627
|
bundle[polyfillChunk.fileName] = polyfillChunk;
|
|
628
|
+
return polyfillChunk;
|
|
626
629
|
}
|
|
627
630
|
const polyfillId = "\0vite/legacy-polyfills";
|
|
628
631
|
function polyfillsPlugin(imports, excludeSystemJS) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-legacy",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Evan You",
|
|
6
6
|
"files": [
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
20
|
"import": "./dist/index.mjs",
|
|
22
21
|
"require": "./dist/index.cjs"
|
|
23
22
|
}
|
|
@@ -36,11 +35,11 @@
|
|
|
36
35
|
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
|
|
37
36
|
"funding": "https://github.com/vitejs/vite?sponsor=1",
|
|
38
37
|
"dependencies": {
|
|
39
|
-
"@babel/core": "^7.
|
|
38
|
+
"@babel/core": "^7.23.0",
|
|
40
39
|
"@babel/preset-env": "^7.22.20",
|
|
41
|
-
"browserslist": "^4.
|
|
42
|
-
"core-js": "^3.
|
|
43
|
-
"magic-string": "^0.30.
|
|
40
|
+
"browserslist": "^4.22.1",
|
|
41
|
+
"core-js": "^3.33.0",
|
|
42
|
+
"magic-string": "^0.30.4",
|
|
44
43
|
"regenerator-runtime": "^0.14.0",
|
|
45
44
|
"systemjs": "^6.14.2"
|
|
46
45
|
},
|
|
@@ -51,7 +50,7 @@
|
|
|
51
50
|
"devDependencies": {
|
|
52
51
|
"acorn": "^8.10.0",
|
|
53
52
|
"picocolors": "^1.0.0",
|
|
54
|
-
"vite": "5.0.0-beta.
|
|
53
|
+
"vite": "5.0.0-beta.5"
|
|
55
54
|
},
|
|
56
55
|
"scripts": {
|
|
57
56
|
"dev": "unbuild --stub",
|