@vitejs/plugin-legacy 4.0.2 → 4.0.4
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 +28 -18
- package/dist/index.mjs +13 -10
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -11,13 +11,20 @@ const MagicString = require('magic-string');
|
|
|
11
11
|
const require$$0 = require('tty');
|
|
12
12
|
const browserslist = require('browserslist');
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
15
|
+
|
|
16
|
+
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
17
|
+
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
18
|
+
const require$$0__default = /*#__PURE__*/_interopDefaultCompat(require$$0);
|
|
19
|
+
const browserslist__default = /*#__PURE__*/_interopDefaultCompat(browserslist);
|
|
20
|
+
|
|
21
|
+
function getDefaultExportFromCjs (x) {
|
|
22
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var picocolors = {exports: {}};
|
|
19
26
|
|
|
20
|
-
let tty = require$$
|
|
27
|
+
let tty = require$$0__default;
|
|
21
28
|
|
|
22
29
|
let isColorSupported =
|
|
23
30
|
!("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
|
|
@@ -74,7 +81,10 @@ let createColors = (enabled = isColorSupported) => ({
|
|
|
74
81
|
});
|
|
75
82
|
|
|
76
83
|
picocolors.exports = createColors();
|
|
77
|
-
|
|
84
|
+
picocolors.exports.createColors = createColors;
|
|
85
|
+
|
|
86
|
+
var picocolorsExports = picocolors.exports;
|
|
87
|
+
const colors = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
|
|
78
88
|
|
|
79
89
|
const safari10NoModuleFix = `!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",(function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()}),!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();`;
|
|
80
90
|
const legacyPolyfillId = "vite-legacy-polyfill";
|
|
@@ -82,7 +92,7 @@ const legacyEntryId = "vite-legacy-entry";
|
|
|
82
92
|
const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`;
|
|
83
93
|
const detectModernBrowserVarName = "__vite_is_modern_browser";
|
|
84
94
|
const detectModernBrowserDetector = 'import.meta.url;import("_").catch(()=>1);async function* g(){};';
|
|
85
|
-
const detectModernBrowserCode = `${detectModernBrowserDetector}window.${detectModernBrowserVarName}=true
|
|
95
|
+
const detectModernBrowserCode = `${detectModernBrowserDetector}if(location.protocol!="file:"){window.${detectModernBrowserVarName}=true}`;
|
|
86
96
|
const dynamicFallbackInlineCode = `!function(){if(window.${detectModernBrowserVarName})return;console.warn("vite: loading legacy chunks, syntax error above and the same error below should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}();`;
|
|
87
97
|
const modernChunkLegacyGuard = `export function __vite_legacy_guard(){${detectModernBrowserDetector}};`;
|
|
88
98
|
|
|
@@ -93,7 +103,7 @@ async function loadBabel() {
|
|
|
93
103
|
}
|
|
94
104
|
return babel;
|
|
95
105
|
}
|
|
96
|
-
const { loadConfig: browserslistLoadConfig } =
|
|
106
|
+
const { loadConfig: browserslistLoadConfig } = browserslist__default;
|
|
97
107
|
function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRelative) {
|
|
98
108
|
const { renderBuiltUrl } = config.experimental;
|
|
99
109
|
let relative = config.base === "" || config.base === "./";
|
|
@@ -124,13 +134,13 @@ function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRela
|
|
|
124
134
|
}
|
|
125
135
|
}
|
|
126
136
|
function getBaseInHTML(urlRelativePath, config) {
|
|
127
|
-
return config.base === "./" || config.base === "" ?
|
|
128
|
-
|
|
137
|
+
return config.base === "./" || config.base === "" ? path__default.posix.join(
|
|
138
|
+
path__default.posix.relative(urlRelativePath, "").slice(0, -2),
|
|
129
139
|
"./"
|
|
130
140
|
) : config.base;
|
|
131
141
|
}
|
|
132
142
|
function toAssetPathFromHtml(filename, htmlPath, config) {
|
|
133
|
-
const relativeUrlPath = vite.normalizePath(
|
|
143
|
+
const relativeUrlPath = vite.normalizePath(path__default.relative(config.root, htmlPath));
|
|
134
144
|
const toRelative = (filename2, hostId) => getBaseInHTML(relativeUrlPath, config) + filename2;
|
|
135
145
|
return toOutputFilePathInHtml(
|
|
136
146
|
filename,
|
|
@@ -208,7 +218,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
208
218
|
configResolved(config2) {
|
|
209
219
|
if (overriddenBuildTarget) {
|
|
210
220
|
config2.logger.warn(
|
|
211
|
-
|
|
221
|
+
colors.yellow(
|
|
212
222
|
`plugin-legacy overrode 'build.target'. You should pass 'targets' as an option to this plugin with the list of legacy browsers to support instead.`
|
|
213
223
|
)
|
|
214
224
|
);
|
|
@@ -286,7 +296,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
286
296
|
isDebug && console.log(`[@vitejs/plugin-legacy] targets:`, targets);
|
|
287
297
|
const getLegacyOutputFileName = (fileNames, defaultFileName = "[name]-legacy-[hash].js") => {
|
|
288
298
|
if (!fileNames) {
|
|
289
|
-
return
|
|
299
|
+
return path__default.posix.join(config.build.assetsDir, defaultFileName);
|
|
290
300
|
}
|
|
291
301
|
return (chunkInfo) => {
|
|
292
302
|
let fileName = typeof fileNames === "function" ? fileNames(chunkInfo) : fileNames;
|
|
@@ -322,7 +332,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
322
332
|
if (options.modernPolyfills && !Array.isArray(options.modernPolyfills)) {
|
|
323
333
|
await detectPolyfills(raw, { esmodules: true }, modernPolyfills);
|
|
324
334
|
}
|
|
325
|
-
const ms = new
|
|
335
|
+
const ms = new MagicString__default(raw);
|
|
326
336
|
if (genLegacy && chunk.isEntry) {
|
|
327
337
|
ms.prepend(modernChunkLegacyGuard);
|
|
328
338
|
}
|
|
@@ -376,7 +386,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
376
386
|
})
|
|
377
387
|
],
|
|
378
388
|
[
|
|
379
|
-
|
|
389
|
+
(await import('@babel/preset-env')).default,
|
|
380
390
|
createBabelPresetEnvOptions(targets, {
|
|
381
391
|
needPolyfills,
|
|
382
392
|
ignoreBrowserslistConfig: options.ignoreBrowserslistConfig
|
|
@@ -521,7 +531,7 @@ async function detectPolyfills(code, targets, list) {
|
|
|
521
531
|
configFile: false,
|
|
522
532
|
presets: [
|
|
523
533
|
[
|
|
524
|
-
|
|
534
|
+
(await import('@babel/preset-env')).default,
|
|
525
535
|
createBabelPresetEnvOptions(targets, {
|
|
526
536
|
ignoreBrowserslistConfig: true
|
|
527
537
|
})
|
|
@@ -561,7 +571,7 @@ async function buildPolyfillChunk(mode, imports, bundle, facadeToChunkMap, build
|
|
|
561
571
|
const res = await vite.build({
|
|
562
572
|
mode,
|
|
563
573
|
// so that everything is resolved from here
|
|
564
|
-
root:
|
|
574
|
+
root: path__default.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)))),
|
|
565
575
|
configFile: false,
|
|
566
576
|
logLevel: "error",
|
|
567
577
|
plugins: [polyfillsPlugin(imports, excludeSystemJS)],
|
package/dist/index.mjs
CHANGED
|
@@ -7,11 +7,11 @@ import MagicString from 'magic-string';
|
|
|
7
7
|
import require$$0 from 'tty';
|
|
8
8
|
import browserslist from 'browserslist';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
10
|
+
function getDefaultExportFromCjs (x) {
|
|
11
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var picocolors = {exports: {}};
|
|
15
15
|
|
|
16
16
|
let tty = require$$0;
|
|
17
17
|
|
|
@@ -70,7 +70,10 @@ let createColors = (enabled = isColorSupported) => ({
|
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
picocolors.exports = createColors();
|
|
73
|
-
|
|
73
|
+
picocolors.exports.createColors = createColors;
|
|
74
|
+
|
|
75
|
+
var picocolorsExports = picocolors.exports;
|
|
76
|
+
const colors = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
|
|
74
77
|
|
|
75
78
|
const safari10NoModuleFix = `!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",(function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()}),!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();`;
|
|
76
79
|
const legacyPolyfillId = "vite-legacy-polyfill";
|
|
@@ -78,7 +81,7 @@ const legacyEntryId = "vite-legacy-entry";
|
|
|
78
81
|
const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`;
|
|
79
82
|
const detectModernBrowserVarName = "__vite_is_modern_browser";
|
|
80
83
|
const detectModernBrowserDetector = 'import.meta.url;import("_").catch(()=>1);async function* g(){};';
|
|
81
|
-
const detectModernBrowserCode = `${detectModernBrowserDetector}window.${detectModernBrowserVarName}=true
|
|
84
|
+
const detectModernBrowserCode = `${detectModernBrowserDetector}if(location.protocol!="file:"){window.${detectModernBrowserVarName}=true}`;
|
|
82
85
|
const dynamicFallbackInlineCode = `!function(){if(window.${detectModernBrowserVarName})return;console.warn("vite: loading legacy chunks, syntax error above and the same error below should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}();`;
|
|
83
86
|
const modernChunkLegacyGuard = `export function __vite_legacy_guard(){${detectModernBrowserDetector}};`;
|
|
84
87
|
|
|
@@ -204,7 +207,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
204
207
|
configResolved(config2) {
|
|
205
208
|
if (overriddenBuildTarget) {
|
|
206
209
|
config2.logger.warn(
|
|
207
|
-
|
|
210
|
+
colors.yellow(
|
|
208
211
|
`plugin-legacy overrode 'build.target'. You should pass 'targets' as an option to this plugin with the list of legacy browsers to support instead.`
|
|
209
212
|
)
|
|
210
213
|
);
|
|
@@ -372,7 +375,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
372
375
|
})
|
|
373
376
|
],
|
|
374
377
|
[
|
|
375
|
-
|
|
378
|
+
(await import('@babel/preset-env')).default,
|
|
376
379
|
createBabelPresetEnvOptions(targets, {
|
|
377
380
|
needPolyfills,
|
|
378
381
|
ignoreBrowserslistConfig: options.ignoreBrowserslistConfig
|
|
@@ -517,7 +520,7 @@ async function detectPolyfills(code, targets, list) {
|
|
|
517
520
|
configFile: false,
|
|
518
521
|
presets: [
|
|
519
522
|
[
|
|
520
|
-
|
|
523
|
+
(await import('@babel/preset-env')).default,
|
|
521
524
|
createBabelPresetEnvOptions(targets, {
|
|
522
525
|
ignoreBrowserslistConfig: true
|
|
523
526
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-legacy",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Evan You",
|
|
6
6
|
"files": [
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@babel/core": "^7.21.
|
|
45
|
-
"@babel/preset-env": "^7.
|
|
44
|
+
"@babel/core": "^7.21.4",
|
|
45
|
+
"@babel/preset-env": "^7.21.4",
|
|
46
46
|
"browserslist": "^4.21.5",
|
|
47
|
-
"core-js": "^3.
|
|
47
|
+
"core-js": "^3.30.1",
|
|
48
48
|
"magic-string": "^0.30.0",
|
|
49
49
|
"regenerator-runtime": "^0.13.11",
|
|
50
|
-
"systemjs": "^6.14.
|
|
50
|
+
"systemjs": "^6.14.1"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"terser": "^5.4.0",
|