@vitejs/plugin-legacy 2.1.0 → 2.3.0-beta.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/README.md +1 -1
- package/dist/index.cjs +83 -0
- package/dist/index.mjs +82 -0
- package/package.json +7 -6
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 default browser support baseline is [Native ESM](https://caniuse.com/es6-module). This plugin provides support for legacy browsers that do not support
|
|
3
|
+
Vite's default browser support baseline is [Native ESM](https://caniuse.com/es6-module), [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
|
|
package/dist/index.cjs
CHANGED
|
@@ -8,11 +8,74 @@ const node_module = require('node:module');
|
|
|
8
8
|
const node_url = require('node:url');
|
|
9
9
|
const vite = require('vite');
|
|
10
10
|
const MagicString = require('magic-string');
|
|
11
|
+
const require$$0 = require('tty');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
13
14
|
|
|
14
15
|
const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
15
16
|
const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
|
|
17
|
+
const require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
18
|
+
|
|
19
|
+
var picocolors = {exports: {}};
|
|
20
|
+
|
|
21
|
+
let tty = require$$0__default;
|
|
22
|
+
|
|
23
|
+
let isColorSupported =
|
|
24
|
+
!("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
|
|
25
|
+
("FORCE_COLOR" in process.env ||
|
|
26
|
+
process.argv.includes("--color") ||
|
|
27
|
+
process.platform === "win32" ||
|
|
28
|
+
(tty.isatty(1) && process.env.TERM !== "dumb") ||
|
|
29
|
+
"CI" in process.env);
|
|
30
|
+
|
|
31
|
+
let formatter =
|
|
32
|
+
(open, close, replace = open) =>
|
|
33
|
+
input => {
|
|
34
|
+
let string = "" + input;
|
|
35
|
+
let index = string.indexOf(close, open.length);
|
|
36
|
+
return ~index
|
|
37
|
+
? open + replaceClose(string, close, replace, index) + close
|
|
38
|
+
: open + string + close
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let replaceClose = (string, close, replace, index) => {
|
|
42
|
+
let start = string.substring(0, index) + replace;
|
|
43
|
+
let end = string.substring(index + close.length);
|
|
44
|
+
let nextIndex = end.indexOf(close);
|
|
45
|
+
return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
let createColors = (enabled = isColorSupported) => ({
|
|
49
|
+
isColorSupported: enabled,
|
|
50
|
+
reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
|
|
51
|
+
bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
|
|
52
|
+
dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
|
|
53
|
+
italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
|
|
54
|
+
underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
|
|
55
|
+
inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
|
|
56
|
+
hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
|
|
57
|
+
strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
|
|
58
|
+
black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
|
|
59
|
+
red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
|
|
60
|
+
green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
|
|
61
|
+
yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
|
|
62
|
+
blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
|
|
63
|
+
magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
|
|
64
|
+
cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
|
|
65
|
+
white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
|
|
66
|
+
gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
|
|
67
|
+
bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
|
|
68
|
+
bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
|
|
69
|
+
bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
|
|
70
|
+
bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
|
|
71
|
+
bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
|
|
72
|
+
bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
|
|
73
|
+
bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
|
|
74
|
+
bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
picocolors.exports = createColors();
|
|
78
|
+
picocolors.exports.createColors = createColors;
|
|
16
79
|
|
|
17
80
|
let babel;
|
|
18
81
|
async function loadBabel() {
|
|
@@ -113,6 +176,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
113
176
|
legacyPolyfills.add(i);
|
|
114
177
|
});
|
|
115
178
|
}
|
|
179
|
+
let overriddenBuildTarget = false;
|
|
116
180
|
const legacyConfigPlugin = {
|
|
117
181
|
name: "vite:legacy-config",
|
|
118
182
|
config(config2, env) {
|
|
@@ -123,12 +187,31 @@ function viteLegacyPlugin(options = {}) {
|
|
|
123
187
|
if (!config2.build.cssTarget) {
|
|
124
188
|
config2.build.cssTarget = "chrome61";
|
|
125
189
|
}
|
|
190
|
+
if (genLegacy) {
|
|
191
|
+
overriddenBuildTarget = config2.build.target !== void 0;
|
|
192
|
+
config2.build.target = [
|
|
193
|
+
"es2020",
|
|
194
|
+
"edge79",
|
|
195
|
+
"firefox67",
|
|
196
|
+
"chrome64",
|
|
197
|
+
"safari11.1"
|
|
198
|
+
];
|
|
199
|
+
}
|
|
126
200
|
}
|
|
127
201
|
return {
|
|
128
202
|
define: {
|
|
129
203
|
"import.meta.env.LEGACY": env.command === "serve" || config2.build?.ssr ? false : legacyEnvVarMarker
|
|
130
204
|
}
|
|
131
205
|
};
|
|
206
|
+
},
|
|
207
|
+
configResolved(config2) {
|
|
208
|
+
if (overriddenBuildTarget) {
|
|
209
|
+
config2.logger.warn(
|
|
210
|
+
picocolors.exports.yellow(
|
|
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.`
|
|
212
|
+
)
|
|
213
|
+
);
|
|
214
|
+
}
|
|
132
215
|
}
|
|
133
216
|
};
|
|
134
217
|
const legacyGenerateBundlePlugin = {
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,68 @@ import { createRequire } from 'node:module';
|
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { build, normalizePath } from 'vite';
|
|
6
6
|
import MagicString from 'magic-string';
|
|
7
|
+
import require$$0 from 'tty';
|
|
8
|
+
|
|
9
|
+
var picocolors = {exports: {}};
|
|
10
|
+
|
|
11
|
+
let tty = require$$0;
|
|
12
|
+
|
|
13
|
+
let isColorSupported =
|
|
14
|
+
!("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
|
|
15
|
+
("FORCE_COLOR" in process.env ||
|
|
16
|
+
process.argv.includes("--color") ||
|
|
17
|
+
process.platform === "win32" ||
|
|
18
|
+
(tty.isatty(1) && process.env.TERM !== "dumb") ||
|
|
19
|
+
"CI" in process.env);
|
|
20
|
+
|
|
21
|
+
let formatter =
|
|
22
|
+
(open, close, replace = open) =>
|
|
23
|
+
input => {
|
|
24
|
+
let string = "" + input;
|
|
25
|
+
let index = string.indexOf(close, open.length);
|
|
26
|
+
return ~index
|
|
27
|
+
? open + replaceClose(string, close, replace, index) + close
|
|
28
|
+
: open + string + close
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
let replaceClose = (string, close, replace, index) => {
|
|
32
|
+
let start = string.substring(0, index) + replace;
|
|
33
|
+
let end = string.substring(index + close.length);
|
|
34
|
+
let nextIndex = end.indexOf(close);
|
|
35
|
+
return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
let createColors = (enabled = isColorSupported) => ({
|
|
39
|
+
isColorSupported: enabled,
|
|
40
|
+
reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
|
|
41
|
+
bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
|
|
42
|
+
dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
|
|
43
|
+
italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
|
|
44
|
+
underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
|
|
45
|
+
inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
|
|
46
|
+
hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
|
|
47
|
+
strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
|
|
48
|
+
black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
|
|
49
|
+
red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
|
|
50
|
+
green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
|
|
51
|
+
yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
|
|
52
|
+
blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
|
|
53
|
+
magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
|
|
54
|
+
cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
|
|
55
|
+
white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
|
|
56
|
+
gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
|
|
57
|
+
bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
|
|
58
|
+
bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
|
|
59
|
+
bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
|
|
60
|
+
bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
|
|
61
|
+
bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
|
|
62
|
+
bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
|
|
63
|
+
bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
|
|
64
|
+
bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
picocolors.exports = createColors();
|
|
68
|
+
picocolors.exports.createColors = createColors;
|
|
7
69
|
|
|
8
70
|
let babel;
|
|
9
71
|
async function loadBabel() {
|
|
@@ -104,6 +166,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
104
166
|
legacyPolyfills.add(i);
|
|
105
167
|
});
|
|
106
168
|
}
|
|
169
|
+
let overriddenBuildTarget = false;
|
|
107
170
|
const legacyConfigPlugin = {
|
|
108
171
|
name: "vite:legacy-config",
|
|
109
172
|
config(config2, env) {
|
|
@@ -114,12 +177,31 @@ function viteLegacyPlugin(options = {}) {
|
|
|
114
177
|
if (!config2.build.cssTarget) {
|
|
115
178
|
config2.build.cssTarget = "chrome61";
|
|
116
179
|
}
|
|
180
|
+
if (genLegacy) {
|
|
181
|
+
overriddenBuildTarget = config2.build.target !== void 0;
|
|
182
|
+
config2.build.target = [
|
|
183
|
+
"es2020",
|
|
184
|
+
"edge79",
|
|
185
|
+
"firefox67",
|
|
186
|
+
"chrome64",
|
|
187
|
+
"safari11.1"
|
|
188
|
+
];
|
|
189
|
+
}
|
|
117
190
|
}
|
|
118
191
|
return {
|
|
119
192
|
define: {
|
|
120
193
|
"import.meta.env.LEGACY": env.command === "serve" || config2.build?.ssr ? false : legacyEnvVarMarker
|
|
121
194
|
}
|
|
122
195
|
};
|
|
196
|
+
},
|
|
197
|
+
configResolved(config2) {
|
|
198
|
+
if (overriddenBuildTarget) {
|
|
199
|
+
config2.logger.warn(
|
|
200
|
+
picocolors.exports.yellow(
|
|
201
|
+
`plugin-legacy overrode 'build.target'. You should pass 'targets' as an option to this plugin with the list of legacy browsers to support instead.`
|
|
202
|
+
)
|
|
203
|
+
);
|
|
204
|
+
}
|
|
123
205
|
}
|
|
124
206
|
};
|
|
125
207
|
const legacyGenerateBundlePlugin = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-legacy",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-beta.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Evan You",
|
|
6
6
|
"files": [
|
|
@@ -35,18 +35,19 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@babel/standalone": "^7.
|
|
39
|
-
"core-js": "^3.25.
|
|
40
|
-
"magic-string": "^0.26.
|
|
38
|
+
"@babel/standalone": "^7.19.3",
|
|
39
|
+
"core-js": "^3.25.4",
|
|
40
|
+
"magic-string": "^0.26.5",
|
|
41
41
|
"regenerator-runtime": "^0.13.9",
|
|
42
|
-
"systemjs": "^6.
|
|
42
|
+
"systemjs": "^6.13.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"terser": "^5.4.0",
|
|
46
46
|
"vite": "^3.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@babel/core": "^7.
|
|
49
|
+
"@babel/core": "^7.19.3",
|
|
50
|
+
"picocolors": "^1.0.0",
|
|
50
51
|
"vite": "workspace:*"
|
|
51
52
|
}
|
|
52
53
|
}
|