@vitejs/plugin-legacy 8.0.0-beta.0 → 8.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/dist/index.js +44 -37
- package/package.json +21 -10
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { build, normalizePath } from "vite";
|
|
|
6
6
|
import MagicString from "magic-string";
|
|
7
7
|
import browserslist from "browserslist";
|
|
8
8
|
|
|
9
|
-
//#region
|
|
9
|
+
//#region \0rolldown/runtime.js
|
|
10
10
|
var __create = Object.create;
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
12
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -151,7 +151,7 @@ function joinUrlSegments(a, b) {
|
|
|
151
151
|
}
|
|
152
152
|
function toAssetPathFromHtml(filename, htmlPath, config) {
|
|
153
153
|
const relativeUrlPath = normalizePath(path.relative(config.root, htmlPath));
|
|
154
|
-
const toRelative = (filename
|
|
154
|
+
const toRelative = (filename, _hostId) => getBaseInHTML(relativeUrlPath, config) + filename;
|
|
155
155
|
return toOutputFilePathInHtml(filename, "asset", htmlPath, "html", config, toRelative);
|
|
156
156
|
}
|
|
157
157
|
const legacyEnvVarMarker = `__VITE_IS_LEGACY__`;
|
|
@@ -202,26 +202,26 @@ function viteLegacyPlugin(options = {}) {
|
|
|
202
202
|
return [
|
|
203
203
|
{
|
|
204
204
|
name: "vite:legacy-config",
|
|
205
|
-
async config(config
|
|
206
|
-
if (env
|
|
207
|
-
if (!config
|
|
208
|
-
if (genLegacy && !config
|
|
205
|
+
async config(config, env) {
|
|
206
|
+
if (env.command === "build" && !config.build?.ssr) {
|
|
207
|
+
if (!config.build) config.build = {};
|
|
208
|
+
if (genLegacy && !config.build.cssTarget) config.build.cssTarget = "chrome61";
|
|
209
209
|
if (genLegacy) {
|
|
210
|
-
overriddenBuildTarget = config
|
|
210
|
+
overriddenBuildTarget = config.build.target !== void 0;
|
|
211
211
|
overriddenDefaultModernTargets = options.modernTargets !== void 0;
|
|
212
|
-
} else overriddenBuildTargetOnlyModern = config
|
|
212
|
+
} else overriddenBuildTargetOnlyModern = config.build.target !== void 0;
|
|
213
213
|
if (options.modernTargets) {
|
|
214
214
|
const { default: browserslistToEsbuild } = await import("browserslist-to-esbuild");
|
|
215
|
-
config
|
|
216
|
-
} else config
|
|
215
|
+
config.build.target = browserslistToEsbuild(options.modernTargets);
|
|
216
|
+
} else config.build.target = modernTargetsEsbuild;
|
|
217
217
|
}
|
|
218
|
-
return { define: { "import.meta.env.LEGACY": env
|
|
218
|
+
return { define: { "import.meta.env.LEGACY": env.command === "serve" || config.build?.ssr ? false : legacyEnvVarMarker } };
|
|
219
219
|
},
|
|
220
|
-
configResolved(config
|
|
221
|
-
if (overriddenBuildTarget) config
|
|
222
|
-
if (overriddenBuildTargetOnlyModern) config
|
|
223
|
-
if (overriddenDefaultModernTargets) config
|
|
224
|
-
if (config
|
|
220
|
+
configResolved(config) {
|
|
221
|
+
if (overriddenBuildTarget) config.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.`));
|
|
222
|
+
if (overriddenBuildTargetOnlyModern) config.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.`));
|
|
223
|
+
if (overriddenDefaultModernTargets) config.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.`));
|
|
224
|
+
if (config.isWorker) config.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.`));
|
|
225
225
|
}
|
|
226
226
|
},
|
|
227
227
|
{
|
|
@@ -232,14 +232,14 @@ function viteLegacyPlugin(options = {}) {
|
|
|
232
232
|
const chunkFileNameToPolyfills = outputToChunkFileNameToPolyfills.get(opts);
|
|
233
233
|
if (chunkFileNameToPolyfills == null) throw new Error("Internal @vitejs/plugin-legacy error: discovered polyfills should exist");
|
|
234
234
|
if (!isLegacyBundle(bundle)) {
|
|
235
|
-
for (const { modern } of chunkFileNameToPolyfills.values()) modern.forEach((p
|
|
235
|
+
for (const { modern } of chunkFileNameToPolyfills.values()) modern.forEach((p) => modernPolyfills.add(p));
|
|
236
236
|
if (!modernPolyfills.size) return;
|
|
237
237
|
if (isDebug) console.log(`[@vitejs/plugin-legacy] modern polyfills:`, modernPolyfills);
|
|
238
238
|
await buildPolyfillChunk(this, config.mode, modernPolyfills, bundle, facadeToModernPolyfillMap, config.build, "es", opts, true, genLegacy);
|
|
239
239
|
return;
|
|
240
240
|
}
|
|
241
241
|
if (!genLegacy) return;
|
|
242
|
-
for (const { legacy } of chunkFileNameToPolyfills.values()) legacy.forEach((p
|
|
242
|
+
for (const { legacy } of chunkFileNameToPolyfills.values()) legacy.forEach((p) => legacyPolyfills.add(p));
|
|
243
243
|
if (options.polyfills !== false) await detectPolyfills(`Promise.resolve(); Promise.all();`, targets, assumptions, legacyPolyfills);
|
|
244
244
|
if (legacyPolyfills.size || !options.externalSystemJS) {
|
|
245
245
|
if (isDebug) console.log(`[@vitejs/plugin-legacy] legacy polyfills:`, legacyPolyfills);
|
|
@@ -271,12 +271,12 @@ function viteLegacyPlugin(options = {}) {
|
|
|
271
271
|
return fileName;
|
|
272
272
|
};
|
|
273
273
|
};
|
|
274
|
-
const createLegacyOutput = (options
|
|
274
|
+
const createLegacyOutput = (options = {}) => {
|
|
275
275
|
return {
|
|
276
|
-
...options
|
|
276
|
+
...options,
|
|
277
277
|
format: "esm",
|
|
278
|
-
entryFileNames: getLegacyOutputFileName(options
|
|
279
|
-
chunkFileNames: getLegacyOutputFileName(options
|
|
278
|
+
entryFileNames: getLegacyOutputFileName(options.entryFileNames),
|
|
279
|
+
chunkFileNames: getLegacyOutputFileName(options.chunkFileNames),
|
|
280
280
|
minify: false
|
|
281
281
|
};
|
|
282
282
|
};
|
|
@@ -318,8 +318,8 @@ function viteLegacyPlugin(options = {}) {
|
|
|
318
318
|
outputOptionsForLegacyChunks.add(opts);
|
|
319
319
|
const needPolyfills = options.polyfills !== false && !Array.isArray(options.polyfills);
|
|
320
320
|
const sourceMaps = !!config.build.sourcemap;
|
|
321
|
-
const babel
|
|
322
|
-
const resultSystem = babel
|
|
321
|
+
const babel = await loadBabel();
|
|
322
|
+
const resultSystem = babel.transform(raw, {
|
|
323
323
|
babelrc: false,
|
|
324
324
|
configFile: false,
|
|
325
325
|
ast: true,
|
|
@@ -353,8 +353,8 @@ function viteLegacyPlugin(options = {}) {
|
|
|
353
353
|
}]]
|
|
354
354
|
};
|
|
355
355
|
let result;
|
|
356
|
-
if (resultSystem) result = babel
|
|
357
|
-
else result = babel
|
|
356
|
+
if (resultSystem) result = babel.transformFromAstSync(resultSystem.ast, void 0, babelTransformOptions);
|
|
357
|
+
else result = babel.transform(raw, babelTransformOptions);
|
|
358
358
|
if (result) return {
|
|
359
359
|
code: result.code,
|
|
360
360
|
map: result.map
|
|
@@ -502,9 +502,16 @@ async function buildPolyfillChunk(ctx, mode, imports, bundle, facadeToChunkMap,
|
|
|
502
502
|
if (chunk.type === "chunk" && chunk.facadeModuleId) facadeToChunkMap.set(chunk.facadeModuleId, polyfillChunk.fileName);
|
|
503
503
|
}
|
|
504
504
|
ctx.emitFile({
|
|
505
|
-
type: "
|
|
505
|
+
type: "prebuilt-chunk",
|
|
506
|
+
name: polyfillChunk.name,
|
|
506
507
|
fileName: polyfillChunk.fileName,
|
|
507
|
-
|
|
508
|
+
code: polyfillChunk.code,
|
|
509
|
+
facadeModuleId: polyfillChunk.facadeModuleId ?? void 0,
|
|
510
|
+
isEntry: polyfillChunk.isEntry,
|
|
511
|
+
isDynamicEntry: polyfillChunk.isDynamicEntry,
|
|
512
|
+
exports: [],
|
|
513
|
+
map: polyfillChunk.map ?? void 0,
|
|
514
|
+
sourcemapFileName: polyfillChunk.sourcemapFileName ?? void 0
|
|
508
515
|
});
|
|
509
516
|
if (polyfillChunk.sourcemapFileName) {
|
|
510
517
|
const polyfillChunkMapAsset = _polyfillChunk.output.find((chunk) => chunk.type === "asset" && chunk.fileName === polyfillChunk.sourcemapFileName);
|
|
@@ -555,11 +562,11 @@ function isLegacyBundle(bundle) {
|
|
|
555
562
|
function recordAndRemovePolyfillBabelPlugin(polyfills) {
|
|
556
563
|
return ({ types: t }) => ({
|
|
557
564
|
name: "vite-remove-polyfill-import",
|
|
558
|
-
post({ path
|
|
559
|
-
path
|
|
560
|
-
if (t.isImportDeclaration(p
|
|
561
|
-
polyfills.add(p
|
|
562
|
-
p
|
|
565
|
+
post({ path }) {
|
|
566
|
+
path.get("body").forEach((p) => {
|
|
567
|
+
if (t.isImportDeclaration(p.node)) {
|
|
568
|
+
polyfills.add(p.node.source.value);
|
|
569
|
+
p.remove();
|
|
563
570
|
}
|
|
564
571
|
});
|
|
565
572
|
}
|
|
@@ -568,8 +575,8 @@ function recordAndRemovePolyfillBabelPlugin(polyfills) {
|
|
|
568
575
|
function replaceLegacyEnvBabelPlugin() {
|
|
569
576
|
return ({ types: t }) => ({
|
|
570
577
|
name: "vite-replace-env-legacy",
|
|
571
|
-
visitor: { Identifier(path
|
|
572
|
-
if (path
|
|
578
|
+
visitor: { Identifier(path) {
|
|
579
|
+
if (path.node.name === legacyEnvVarMarker) path.replaceWith(t.booleanLiteral(true));
|
|
573
580
|
} }
|
|
574
581
|
});
|
|
575
582
|
}
|
|
@@ -578,10 +585,10 @@ function wrapIIFEBabelPlugin() {
|
|
|
578
585
|
const buildIIFE = template(";(function(){%%body%%})();");
|
|
579
586
|
return {
|
|
580
587
|
name: "vite-wrap-iife",
|
|
581
|
-
post({ path
|
|
588
|
+
post({ path }) {
|
|
582
589
|
if (!this.isWrapped) {
|
|
583
590
|
this.isWrapped = true;
|
|
584
|
-
path
|
|
591
|
+
path.replaceWith(t.program(buildIIFE({ body: path.node.body })));
|
|
585
592
|
}
|
|
586
593
|
}
|
|
587
594
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-legacy",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Evan You",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
|
|
29
29
|
"funding": "https://github.com/vitejs/vite?sponsor=1",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@babel/core": "^7.
|
|
31
|
+
"@babel/core": "^7.29.0",
|
|
32
32
|
"@babel/plugin-transform-dynamic-import": "^7.27.1",
|
|
33
|
-
"@babel/plugin-transform-modules-systemjs": "^7.
|
|
34
|
-
"@babel/preset-env": "^7.
|
|
35
|
-
"babel-plugin-polyfill-corejs3": "^0.
|
|
36
|
-
"babel-plugin-polyfill-regenerator": "^0.6.
|
|
37
|
-
"browserslist": "^4.28.
|
|
33
|
+
"@babel/plugin-transform-modules-systemjs": "^7.29.0",
|
|
34
|
+
"@babel/preset-env": "^7.29.0",
|
|
35
|
+
"babel-plugin-polyfill-corejs3": "^0.14.0",
|
|
36
|
+
"babel-plugin-polyfill-regenerator": "^0.6.6",
|
|
37
|
+
"browserslist": "^4.28.1",
|
|
38
38
|
"browserslist-to-esbuild": "^2.1.1",
|
|
39
|
-
"core-js": "^3.
|
|
39
|
+
"core-js": "^3.48.0",
|
|
40
40
|
"magic-string": "^0.30.21",
|
|
41
41
|
"regenerator-runtime": "^0.14.1",
|
|
42
42
|
"systemjs": "^6.15.1"
|
|
@@ -48,8 +48,19 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"acorn": "^8.15.0",
|
|
50
50
|
"picocolors": "^1.1.1",
|
|
51
|
-
"tsdown": "^0.
|
|
52
|
-
"vite": "8.0.0-beta.
|
|
51
|
+
"tsdown": "^0.20.1",
|
|
52
|
+
"vite": "8.0.0-beta.12"
|
|
53
|
+
},
|
|
54
|
+
"compatiblePackages": {
|
|
55
|
+
"schemaVersion": 1,
|
|
56
|
+
"rolldown": {
|
|
57
|
+
"type": "incompatible",
|
|
58
|
+
"reason": "Only supports Vite"
|
|
59
|
+
},
|
|
60
|
+
"rollup": {
|
|
61
|
+
"type": "incompatible",
|
|
62
|
+
"reason": "Only supports Vite"
|
|
63
|
+
}
|
|
53
64
|
},
|
|
54
65
|
"scripts": {
|
|
55
66
|
"dev": "tsdown --watch",
|