@vitejs/plugin-legacy 8.0.0-beta.1 → 8.0.0-beta.3
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 -2
- package/dist/index.js +26 -10
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vitejs/plugin-legacy [](https://npmjs.com/package/@vitejs/plugin-legacy)
|
|
2
2
|
|
|
3
|
-
Vite's
|
|
3
|
+
Vite's minimum browser support target is [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import), and [`import.meta`](https://caniuse.com/mdn-javascript_operators_import_meta). This plugin provides support for legacy browsers that do not support those features when building for production.
|
|
4
4
|
|
|
5
5
|
By default, this plugin will:
|
|
6
6
|
|
|
@@ -135,7 +135,7 @@ npm add -D terser
|
|
|
135
135
|
|
|
136
136
|
## Browsers that supports ESM but does not support widely-available features
|
|
137
137
|
|
|
138
|
-
The legacy plugin offers a way to use widely-available features natively in the modern build, while falling back to the legacy build in browsers with native ESM but without those features supported (e.g. Legacy Edge). This feature works by injecting a runtime check and loading the legacy bundle with
|
|
138
|
+
The legacy plugin offers a way to use widely-available features natively in the modern build, while falling back to the legacy build in browsers with native ESM but without those features supported (e.g. Legacy Edge). This feature works by injecting a runtime check and loading the legacy bundle with SystemJS runtime if needed. There are the following drawbacks:
|
|
139
139
|
|
|
140
140
|
- Modern bundle is downloaded in all ESM browsers
|
|
141
141
|
- Modern bundle throws `SyntaxError` in browsers without those features support
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import path
|
|
2
|
+
import path from "node:path";
|
|
3
3
|
import crypto from "node:crypto";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
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;
|
|
@@ -141,7 +141,7 @@ function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRela
|
|
|
141
141
|
else return joinUrlSegments(config.decodedBase, filename);
|
|
142
142
|
}
|
|
143
143
|
function getBaseInHTML(urlRelativePath, config) {
|
|
144
|
-
return config.base === "./" || config.base === "" ? path
|
|
144
|
+
return config.base === "./" || config.base === "" ? path.posix.join(path.posix.relative(urlRelativePath, "").slice(0, -2), "./") : config.base;
|
|
145
145
|
}
|
|
146
146
|
function joinUrlSegments(a, b) {
|
|
147
147
|
if (!a || !b) return a || b || "";
|
|
@@ -150,11 +150,12 @@ function joinUrlSegments(a, b) {
|
|
|
150
150
|
return a + b;
|
|
151
151
|
}
|
|
152
152
|
function toAssetPathFromHtml(filename, htmlPath, config) {
|
|
153
|
-
const relativeUrlPath = normalizePath(path
|
|
153
|
+
const relativeUrlPath = normalizePath(path.relative(config.root, htmlPath));
|
|
154
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__`;
|
|
158
|
+
const modernEnvVarMarker = `__VITE_IS_MODERN__`;
|
|
158
159
|
const _require = createRequire(import.meta.url);
|
|
159
160
|
const nonLeadingHashInFileNameRE = /[^/]+\[hash(?::\d+)?\]/;
|
|
160
161
|
const prefixedHashInFileNameRE = /\W?\[hash(?::\d+)?\]/;
|
|
@@ -262,7 +263,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
262
263
|
targets = options.targets || browserslistLoadConfig({ path: config.root }) || "last 2 versions and not dead, > 0.3%, Firefox ESR";
|
|
263
264
|
if (isDebug) console.log(`[@vitejs/plugin-legacy] targets:`, targets);
|
|
264
265
|
const getLegacyOutputFileName = (fileNames, defaultFileName = "[name]-legacy-[hash].js") => {
|
|
265
|
-
if (!fileNames) return path
|
|
266
|
+
if (!fileNames) return path.posix.join(config.build.assetsDir, defaultFileName);
|
|
266
267
|
return (chunkInfo) => {
|
|
267
268
|
let fileName = typeof fileNames === "function" ? fileNames(chunkInfo) : fileNames;
|
|
268
269
|
if (fileName.includes("[name]")) fileName = fileName.replace("[name]", "[name]-legacy");
|
|
@@ -340,6 +341,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
340
341
|
presets: [[() => ({ plugins: [
|
|
341
342
|
recordAndRemovePolyfillBabelPlugin(polyfillsDiscovered.legacy),
|
|
342
343
|
replaceLegacyEnvBabelPlugin(),
|
|
344
|
+
replaceModernEnvBabelPlugin(),
|
|
343
345
|
wrapIIFEBabelPlugin()
|
|
344
346
|
] })], [(await import("@babel/preset-env")).default, {
|
|
345
347
|
bugfixes: true,
|
|
@@ -472,7 +474,7 @@ async function buildPolyfillChunk(ctx, mode, imports, bundle, facadeToChunkMap,
|
|
|
472
474
|
minify = minify ? "terser" : false;
|
|
473
475
|
const res = await build({
|
|
474
476
|
mode,
|
|
475
|
-
root: path
|
|
477
|
+
root: path.dirname(fileURLToPath(import.meta.url)),
|
|
476
478
|
configFile: false,
|
|
477
479
|
logLevel: "error",
|
|
478
480
|
plugins: [polyfillsPlugin(imports, excludeSystemJS), prependModenChunkLegacyGuard && prependModenChunkLegacyGuardPlugin()],
|
|
@@ -502,9 +504,16 @@ async function buildPolyfillChunk(ctx, mode, imports, bundle, facadeToChunkMap,
|
|
|
502
504
|
if (chunk.type === "chunk" && chunk.facadeModuleId) facadeToChunkMap.set(chunk.facadeModuleId, polyfillChunk.fileName);
|
|
503
505
|
}
|
|
504
506
|
ctx.emitFile({
|
|
505
|
-
type: "
|
|
507
|
+
type: "prebuilt-chunk",
|
|
508
|
+
name: polyfillChunk.name,
|
|
506
509
|
fileName: polyfillChunk.fileName,
|
|
507
|
-
|
|
510
|
+
code: polyfillChunk.code,
|
|
511
|
+
facadeModuleId: polyfillChunk.facadeModuleId ?? void 0,
|
|
512
|
+
isEntry: polyfillChunk.isEntry,
|
|
513
|
+
isDynamicEntry: polyfillChunk.isDynamicEntry,
|
|
514
|
+
exports: [],
|
|
515
|
+
map: polyfillChunk.map ?? void 0,
|
|
516
|
+
sourcemapFileName: polyfillChunk.sourcemapFileName ?? void 0
|
|
508
517
|
});
|
|
509
518
|
if (polyfillChunk.sourcemapFileName) {
|
|
510
519
|
const polyfillChunkMapAsset = _polyfillChunk.output.find((chunk) => chunk.type === "asset" && chunk.fileName === polyfillChunk.sourcemapFileName);
|
|
@@ -573,6 +582,14 @@ function replaceLegacyEnvBabelPlugin() {
|
|
|
573
582
|
} }
|
|
574
583
|
});
|
|
575
584
|
}
|
|
585
|
+
function replaceModernEnvBabelPlugin() {
|
|
586
|
+
return ({ types: t }) => ({
|
|
587
|
+
name: "vite-replace-env-modern",
|
|
588
|
+
visitor: { Identifier(path) {
|
|
589
|
+
if (path.node.name === modernEnvVarMarker) path.replaceWith(t.booleanLiteral(false));
|
|
590
|
+
} }
|
|
591
|
+
});
|
|
592
|
+
}
|
|
576
593
|
function wrapIIFEBabelPlugin() {
|
|
577
594
|
return ({ types: t, template }) => {
|
|
578
595
|
const buildIIFE = template(";(function(){%%body%%})();");
|
|
@@ -593,7 +610,6 @@ const cspHashes = [
|
|
|
593
610
|
detectModernBrowserCode,
|
|
594
611
|
dynamicFallbackInlineCode
|
|
595
612
|
].map((i) => crypto.hash("sha256", i, "base64"));
|
|
596
|
-
var src_default = viteLegacyPlugin;
|
|
597
613
|
function viteLegacyPluginCjs(options) {
|
|
598
614
|
return viteLegacyPlugin.call(this, options);
|
|
599
615
|
}
|
|
@@ -604,4 +620,4 @@ Object.assign(viteLegacyPluginCjs, {
|
|
|
604
620
|
});
|
|
605
621
|
|
|
606
622
|
//#endregion
|
|
607
|
-
export { cspHashes,
|
|
623
|
+
export { cspHashes, viteLegacyPlugin as default, detectPolyfills, viteLegacyPluginCjs as "module.exports" };
|
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.3",
|
|
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.
|
|
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
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,8 @@
|
|
|
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.3",
|
|
52
|
+
"vite": "8.0.0-beta.14"
|
|
53
53
|
},
|
|
54
54
|
"compatiblePackages": {
|
|
55
55
|
"schemaVersion": 1,
|