@vitejs/plugin-legacy 2.0.0-beta.0 → 2.0.1
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/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/index.cjs +130 -24
- package/dist/index.mjs +130 -24
- package/package.json +7 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -163,7 +163,7 @@ Run `node --input-type=module -e "import {cspHashes} from '@vitejs/plugin-legacy
|
|
|
163
163
|
These values (without the `sha256-` prefix) can also be retrieved via
|
|
164
164
|
|
|
165
165
|
```js
|
|
166
|
-
|
|
166
|
+
import { cspHashes } from '@vitejs/plugin-legacy'
|
|
167
167
|
```
|
|
168
168
|
|
|
169
169
|
When using the `regenerator-runtime` polyfill, it will attempt to use the `globalThis` object to register itself. If `globalThis` is not available (it is [fairly new](https://caniuse.com/?search=globalThis) and not widely supported, including IE 11), it attempts to perform dynamic `Function(...)` call which violates the CSP. To avoid dynamic `eval` in the absence of `globalThis` consider adding `core-js/proposals/global-this` to `additionalLegacyPolyfills` to define it.
|
package/dist/index.cjs
CHANGED
|
@@ -21,15 +21,52 @@ async function loadBabel() {
|
|
|
21
21
|
}
|
|
22
22
|
return babel;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
24
|
+
function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRelative) {
|
|
25
|
+
const { renderBuiltUrl } = config.experimental;
|
|
26
|
+
let relative = config.base === "" || config.base === "./";
|
|
27
|
+
if (renderBuiltUrl) {
|
|
28
|
+
const result = renderBuiltUrl(filename, {
|
|
29
|
+
hostId,
|
|
30
|
+
hostType,
|
|
31
|
+
type,
|
|
32
|
+
ssr: !!config.build.ssr
|
|
33
|
+
});
|
|
34
|
+
if (typeof result === "object") {
|
|
35
|
+
if (result.runtime) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`{ runtime: "${result.runtime}" } is not supported for assets in ${hostType} files: ${filename}`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
if (typeof result.relative === "boolean") {
|
|
41
|
+
relative = result.relative;
|
|
42
|
+
}
|
|
43
|
+
} else if (result) {
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (relative && !config.build.ssr) {
|
|
48
|
+
return toRelative(filename, hostId);
|
|
49
|
+
} else {
|
|
50
|
+
return config.base + filename;
|
|
51
|
+
}
|
|
26
52
|
}
|
|
27
|
-
function
|
|
28
|
-
return
|
|
53
|
+
function getBaseInHTML(urlRelativePath, config) {
|
|
54
|
+
return config.base === "./" || config.base === "" ? path__default.posix.join(
|
|
55
|
+
path__default.posix.relative(urlRelativePath, "").slice(0, -2),
|
|
56
|
+
"./"
|
|
57
|
+
) : config.base;
|
|
29
58
|
}
|
|
30
59
|
function toAssetPathFromHtml(filename, htmlPath, config) {
|
|
31
60
|
const relativeUrlPath = vite.normalizePath(path__default.relative(config.root, htmlPath));
|
|
32
|
-
|
|
61
|
+
const toRelative = (filename2, hostId) => getBaseInHTML(relativeUrlPath, config) + filename2;
|
|
62
|
+
return toOutputFilePathInHtml(
|
|
63
|
+
filename,
|
|
64
|
+
"asset",
|
|
65
|
+
htmlPath,
|
|
66
|
+
"html",
|
|
67
|
+
config,
|
|
68
|
+
toRelative
|
|
69
|
+
);
|
|
33
70
|
}
|
|
34
71
|
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()}}();`;
|
|
35
72
|
const legacyPolyfillId = "vite-legacy-polyfill";
|
|
@@ -55,7 +92,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
55
92
|
const legacyPolyfills = /* @__PURE__ */ new Set();
|
|
56
93
|
if (Array.isArray(options.modernPolyfills)) {
|
|
57
94
|
options.modernPolyfills.forEach((i) => {
|
|
58
|
-
modernPolyfills.add(
|
|
95
|
+
modernPolyfills.add(
|
|
96
|
+
i.includes("/") ? `core-js/${i}` : `core-js/modules/${i}.js`
|
|
97
|
+
);
|
|
59
98
|
});
|
|
60
99
|
}
|
|
61
100
|
if (Array.isArray(options.polyfills)) {
|
|
@@ -63,7 +102,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
63
102
|
if (i.startsWith(`regenerator`)) {
|
|
64
103
|
legacyPolyfills.add(`regenerator-runtime/runtime.js`);
|
|
65
104
|
} else {
|
|
66
|
-
legacyPolyfills.add(
|
|
105
|
+
legacyPolyfills.add(
|
|
106
|
+
i.includes("/") ? `core-js/${i}` : `core-js/modules/${i}.js`
|
|
107
|
+
);
|
|
67
108
|
}
|
|
68
109
|
});
|
|
69
110
|
}
|
|
@@ -95,17 +136,43 @@ function viteLegacyPlugin(options = {}) {
|
|
|
95
136
|
if (!modernPolyfills.size) {
|
|
96
137
|
return;
|
|
97
138
|
}
|
|
98
|
-
isDebug && console.log(
|
|
99
|
-
|
|
139
|
+
isDebug && console.log(
|
|
140
|
+
`[@vitejs/plugin-legacy] modern polyfills:`,
|
|
141
|
+
modernPolyfills
|
|
142
|
+
);
|
|
143
|
+
await buildPolyfillChunk(
|
|
144
|
+
modernPolyfills,
|
|
145
|
+
bundle,
|
|
146
|
+
facadeToModernPolyfillMap,
|
|
147
|
+
config.build,
|
|
148
|
+
"es",
|
|
149
|
+
opts,
|
|
150
|
+
true
|
|
151
|
+
);
|
|
100
152
|
return;
|
|
101
153
|
}
|
|
102
154
|
if (!genLegacy) {
|
|
103
155
|
return;
|
|
104
156
|
}
|
|
105
157
|
if (legacyPolyfills.size || genDynamicFallback) {
|
|
106
|
-
await detectPolyfills(
|
|
107
|
-
|
|
108
|
-
|
|
158
|
+
await detectPolyfills(
|
|
159
|
+
`Promise.resolve(); Promise.all();`,
|
|
160
|
+
targets,
|
|
161
|
+
legacyPolyfills
|
|
162
|
+
);
|
|
163
|
+
isDebug && console.log(
|
|
164
|
+
`[@vitejs/plugin-legacy] legacy polyfills:`,
|
|
165
|
+
legacyPolyfills
|
|
166
|
+
);
|
|
167
|
+
await buildPolyfillChunk(
|
|
168
|
+
legacyPolyfills,
|
|
169
|
+
bundle,
|
|
170
|
+
facadeToLegacyPolyfillMap,
|
|
171
|
+
config.build,
|
|
172
|
+
"iife",
|
|
173
|
+
opts,
|
|
174
|
+
options.externalSystemJS
|
|
175
|
+
);
|
|
109
176
|
}
|
|
110
177
|
}
|
|
111
178
|
};
|
|
@@ -167,7 +234,11 @@ function viteLegacyPlugin(options = {}) {
|
|
|
167
234
|
const re = new RegExp(legacyEnvVarMarker, "g");
|
|
168
235
|
let match;
|
|
169
236
|
while (match = re.exec(raw)) {
|
|
170
|
-
ms.overwrite(
|
|
237
|
+
ms.overwrite(
|
|
238
|
+
match.index,
|
|
239
|
+
match.index + legacyEnvVarMarker.length,
|
|
240
|
+
`false`
|
|
241
|
+
);
|
|
171
242
|
}
|
|
172
243
|
}
|
|
173
244
|
if (config.build.sourcemap) {
|
|
@@ -229,18 +300,26 @@ function viteLegacyPlugin(options = {}) {
|
|
|
229
300
|
}
|
|
230
301
|
const tags = [];
|
|
231
302
|
const htmlFilename = chunk.facadeModuleId?.replace(/\?.*$/, "");
|
|
232
|
-
const modernPolyfillFilename = facadeToModernPolyfillMap.get(
|
|
303
|
+
const modernPolyfillFilename = facadeToModernPolyfillMap.get(
|
|
304
|
+
chunk.facadeModuleId
|
|
305
|
+
);
|
|
233
306
|
if (modernPolyfillFilename) {
|
|
234
307
|
tags.push({
|
|
235
308
|
tag: "script",
|
|
236
309
|
attrs: {
|
|
237
310
|
type: "module",
|
|
238
311
|
crossorigin: true,
|
|
239
|
-
src: toAssetPathFromHtml(
|
|
312
|
+
src: toAssetPathFromHtml(
|
|
313
|
+
modernPolyfillFilename,
|
|
314
|
+
chunk.facadeModuleId,
|
|
315
|
+
config
|
|
316
|
+
)
|
|
240
317
|
}
|
|
241
318
|
});
|
|
242
319
|
} else if (modernPolyfills.size) {
|
|
243
|
-
throw new Error(
|
|
320
|
+
throw new Error(
|
|
321
|
+
`No corresponding modern polyfill chunk found for ${htmlFilename}`
|
|
322
|
+
);
|
|
244
323
|
}
|
|
245
324
|
if (!genLegacy) {
|
|
246
325
|
return { html, tags };
|
|
@@ -251,7 +330,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
251
330
|
children: safari10NoModuleFix,
|
|
252
331
|
injectTo: "body"
|
|
253
332
|
});
|
|
254
|
-
const legacyPolyfillFilename = facadeToLegacyPolyfillMap.get(
|
|
333
|
+
const legacyPolyfillFilename = facadeToLegacyPolyfillMap.get(
|
|
334
|
+
chunk.facadeModuleId
|
|
335
|
+
);
|
|
255
336
|
if (legacyPolyfillFilename) {
|
|
256
337
|
tags.push({
|
|
257
338
|
tag: "script",
|
|
@@ -259,14 +340,22 @@ function viteLegacyPlugin(options = {}) {
|
|
|
259
340
|
nomodule: true,
|
|
260
341
|
crossorigin: true,
|
|
261
342
|
id: legacyPolyfillId,
|
|
262
|
-
src: toAssetPathFromHtml(
|
|
343
|
+
src: toAssetPathFromHtml(
|
|
344
|
+
legacyPolyfillFilename,
|
|
345
|
+
chunk.facadeModuleId,
|
|
346
|
+
config
|
|
347
|
+
)
|
|
263
348
|
},
|
|
264
349
|
injectTo: "body"
|
|
265
350
|
});
|
|
266
351
|
} else if (legacyPolyfills.size) {
|
|
267
|
-
throw new Error(
|
|
352
|
+
throw new Error(
|
|
353
|
+
`No corresponding legacy polyfill chunk found for ${htmlFilename}`
|
|
354
|
+
);
|
|
268
355
|
}
|
|
269
|
-
const legacyEntryFilename = facadeToLegacyChunkMap.get(
|
|
356
|
+
const legacyEntryFilename = facadeToLegacyChunkMap.get(
|
|
357
|
+
chunk.facadeModuleId
|
|
358
|
+
);
|
|
270
359
|
if (legacyEntryFilename) {
|
|
271
360
|
tags.push({
|
|
272
361
|
tag: "script",
|
|
@@ -274,13 +363,19 @@ function viteLegacyPlugin(options = {}) {
|
|
|
274
363
|
nomodule: true,
|
|
275
364
|
crossorigin: true,
|
|
276
365
|
id: legacyEntryId,
|
|
277
|
-
"data-src": toAssetPathFromHtml(
|
|
366
|
+
"data-src": toAssetPathFromHtml(
|
|
367
|
+
legacyEntryFilename,
|
|
368
|
+
chunk.facadeModuleId,
|
|
369
|
+
config
|
|
370
|
+
)
|
|
278
371
|
},
|
|
279
372
|
children: systemJSInlineCode,
|
|
280
373
|
injectTo: "body"
|
|
281
374
|
});
|
|
282
375
|
} else {
|
|
283
|
-
throw new Error(
|
|
376
|
+
throw new Error(
|
|
377
|
+
`No corresponding legacy entry chunk found for ${htmlFilename}`
|
|
378
|
+
);
|
|
284
379
|
}
|
|
285
380
|
if (genDynamicFallback && legacyPolyfillFilename && legacyEntryFilename) {
|
|
286
381
|
tags.push({
|
|
@@ -330,7 +425,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
330
425
|
},
|
|
331
426
|
configResolved(config2) {
|
|
332
427
|
if (envInjectionFailed) {
|
|
333
|
-
config2.logger.warn(
|
|
428
|
+
config2.logger.warn(
|
|
429
|
+
`[@vitejs/plugin-legacy] import.meta.env.LEGACY was not injected due to incompatible vite version (requires vite@^2.0.0-beta.69).`
|
|
430
|
+
);
|
|
334
431
|
}
|
|
335
432
|
}
|
|
336
433
|
};
|
|
@@ -431,6 +528,13 @@ function polyfillsPlugin(imports, excludeSystemJS) {
|
|
|
431
528
|
if (id === polyfillId) {
|
|
432
529
|
return [...imports].map((i) => `import "${i}";`).join("") + (excludeSystemJS ? "" : `import "systemjs/dist/s.min.js";`);
|
|
433
530
|
}
|
|
531
|
+
},
|
|
532
|
+
renderChunk(_, __, opts) {
|
|
533
|
+
if (!excludeSystemJS) {
|
|
534
|
+
opts.__vite_skip_esbuild__ = true;
|
|
535
|
+
opts.__vite_force_terser__ = true;
|
|
536
|
+
}
|
|
537
|
+
return null;
|
|
434
538
|
}
|
|
435
539
|
};
|
|
436
540
|
}
|
|
@@ -439,7 +543,9 @@ function isLegacyChunk(chunk, options) {
|
|
|
439
543
|
}
|
|
440
544
|
function isLegacyBundle(bundle, options) {
|
|
441
545
|
if (options.format === "system") {
|
|
442
|
-
const entryChunk = Object.values(bundle).find(
|
|
546
|
+
const entryChunk = Object.values(bundle).find(
|
|
547
|
+
(output) => output.type === "chunk" && output.isEntry
|
|
548
|
+
);
|
|
443
549
|
return !!entryChunk && entryChunk.fileName.includes("-legacy");
|
|
444
550
|
}
|
|
445
551
|
return false;
|
package/dist/index.mjs
CHANGED
|
@@ -12,15 +12,52 @@ async function loadBabel() {
|
|
|
12
12
|
}
|
|
13
13
|
return babel;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
15
|
+
function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRelative) {
|
|
16
|
+
const { renderBuiltUrl } = config.experimental;
|
|
17
|
+
let relative = config.base === "" || config.base === "./";
|
|
18
|
+
if (renderBuiltUrl) {
|
|
19
|
+
const result = renderBuiltUrl(filename, {
|
|
20
|
+
hostId,
|
|
21
|
+
hostType,
|
|
22
|
+
type,
|
|
23
|
+
ssr: !!config.build.ssr
|
|
24
|
+
});
|
|
25
|
+
if (typeof result === "object") {
|
|
26
|
+
if (result.runtime) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`{ runtime: "${result.runtime}" } is not supported for assets in ${hostType} files: ${filename}`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
if (typeof result.relative === "boolean") {
|
|
32
|
+
relative = result.relative;
|
|
33
|
+
}
|
|
34
|
+
} else if (result) {
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (relative && !config.build.ssr) {
|
|
39
|
+
return toRelative(filename, hostId);
|
|
40
|
+
} else {
|
|
41
|
+
return config.base + filename;
|
|
42
|
+
}
|
|
17
43
|
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
44
|
+
function getBaseInHTML(urlRelativePath, config) {
|
|
45
|
+
return config.base === "./" || config.base === "" ? path.posix.join(
|
|
46
|
+
path.posix.relative(urlRelativePath, "").slice(0, -2),
|
|
47
|
+
"./"
|
|
48
|
+
) : config.base;
|
|
20
49
|
}
|
|
21
50
|
function toAssetPathFromHtml(filename, htmlPath, config) {
|
|
22
51
|
const relativeUrlPath = normalizePath(path.relative(config.root, htmlPath));
|
|
23
|
-
|
|
52
|
+
const toRelative = (filename2, hostId) => getBaseInHTML(relativeUrlPath, config) + filename2;
|
|
53
|
+
return toOutputFilePathInHtml(
|
|
54
|
+
filename,
|
|
55
|
+
"asset",
|
|
56
|
+
htmlPath,
|
|
57
|
+
"html",
|
|
58
|
+
config,
|
|
59
|
+
toRelative
|
|
60
|
+
);
|
|
24
61
|
}
|
|
25
62
|
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()}}();`;
|
|
26
63
|
const legacyPolyfillId = "vite-legacy-polyfill";
|
|
@@ -46,7 +83,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
46
83
|
const legacyPolyfills = /* @__PURE__ */ new Set();
|
|
47
84
|
if (Array.isArray(options.modernPolyfills)) {
|
|
48
85
|
options.modernPolyfills.forEach((i) => {
|
|
49
|
-
modernPolyfills.add(
|
|
86
|
+
modernPolyfills.add(
|
|
87
|
+
i.includes("/") ? `core-js/${i}` : `core-js/modules/${i}.js`
|
|
88
|
+
);
|
|
50
89
|
});
|
|
51
90
|
}
|
|
52
91
|
if (Array.isArray(options.polyfills)) {
|
|
@@ -54,7 +93,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
54
93
|
if (i.startsWith(`regenerator`)) {
|
|
55
94
|
legacyPolyfills.add(`regenerator-runtime/runtime.js`);
|
|
56
95
|
} else {
|
|
57
|
-
legacyPolyfills.add(
|
|
96
|
+
legacyPolyfills.add(
|
|
97
|
+
i.includes("/") ? `core-js/${i}` : `core-js/modules/${i}.js`
|
|
98
|
+
);
|
|
58
99
|
}
|
|
59
100
|
});
|
|
60
101
|
}
|
|
@@ -86,17 +127,43 @@ function viteLegacyPlugin(options = {}) {
|
|
|
86
127
|
if (!modernPolyfills.size) {
|
|
87
128
|
return;
|
|
88
129
|
}
|
|
89
|
-
isDebug && console.log(
|
|
90
|
-
|
|
130
|
+
isDebug && console.log(
|
|
131
|
+
`[@vitejs/plugin-legacy] modern polyfills:`,
|
|
132
|
+
modernPolyfills
|
|
133
|
+
);
|
|
134
|
+
await buildPolyfillChunk(
|
|
135
|
+
modernPolyfills,
|
|
136
|
+
bundle,
|
|
137
|
+
facadeToModernPolyfillMap,
|
|
138
|
+
config.build,
|
|
139
|
+
"es",
|
|
140
|
+
opts,
|
|
141
|
+
true
|
|
142
|
+
);
|
|
91
143
|
return;
|
|
92
144
|
}
|
|
93
145
|
if (!genLegacy) {
|
|
94
146
|
return;
|
|
95
147
|
}
|
|
96
148
|
if (legacyPolyfills.size || genDynamicFallback) {
|
|
97
|
-
await detectPolyfills(
|
|
98
|
-
|
|
99
|
-
|
|
149
|
+
await detectPolyfills(
|
|
150
|
+
`Promise.resolve(); Promise.all();`,
|
|
151
|
+
targets,
|
|
152
|
+
legacyPolyfills
|
|
153
|
+
);
|
|
154
|
+
isDebug && console.log(
|
|
155
|
+
`[@vitejs/plugin-legacy] legacy polyfills:`,
|
|
156
|
+
legacyPolyfills
|
|
157
|
+
);
|
|
158
|
+
await buildPolyfillChunk(
|
|
159
|
+
legacyPolyfills,
|
|
160
|
+
bundle,
|
|
161
|
+
facadeToLegacyPolyfillMap,
|
|
162
|
+
config.build,
|
|
163
|
+
"iife",
|
|
164
|
+
opts,
|
|
165
|
+
options.externalSystemJS
|
|
166
|
+
);
|
|
100
167
|
}
|
|
101
168
|
}
|
|
102
169
|
};
|
|
@@ -158,7 +225,11 @@ function viteLegacyPlugin(options = {}) {
|
|
|
158
225
|
const re = new RegExp(legacyEnvVarMarker, "g");
|
|
159
226
|
let match;
|
|
160
227
|
while (match = re.exec(raw)) {
|
|
161
|
-
ms.overwrite(
|
|
228
|
+
ms.overwrite(
|
|
229
|
+
match.index,
|
|
230
|
+
match.index + legacyEnvVarMarker.length,
|
|
231
|
+
`false`
|
|
232
|
+
);
|
|
162
233
|
}
|
|
163
234
|
}
|
|
164
235
|
if (config.build.sourcemap) {
|
|
@@ -220,18 +291,26 @@ function viteLegacyPlugin(options = {}) {
|
|
|
220
291
|
}
|
|
221
292
|
const tags = [];
|
|
222
293
|
const htmlFilename = chunk.facadeModuleId?.replace(/\?.*$/, "");
|
|
223
|
-
const modernPolyfillFilename = facadeToModernPolyfillMap.get(
|
|
294
|
+
const modernPolyfillFilename = facadeToModernPolyfillMap.get(
|
|
295
|
+
chunk.facadeModuleId
|
|
296
|
+
);
|
|
224
297
|
if (modernPolyfillFilename) {
|
|
225
298
|
tags.push({
|
|
226
299
|
tag: "script",
|
|
227
300
|
attrs: {
|
|
228
301
|
type: "module",
|
|
229
302
|
crossorigin: true,
|
|
230
|
-
src: toAssetPathFromHtml(
|
|
303
|
+
src: toAssetPathFromHtml(
|
|
304
|
+
modernPolyfillFilename,
|
|
305
|
+
chunk.facadeModuleId,
|
|
306
|
+
config
|
|
307
|
+
)
|
|
231
308
|
}
|
|
232
309
|
});
|
|
233
310
|
} else if (modernPolyfills.size) {
|
|
234
|
-
throw new Error(
|
|
311
|
+
throw new Error(
|
|
312
|
+
`No corresponding modern polyfill chunk found for ${htmlFilename}`
|
|
313
|
+
);
|
|
235
314
|
}
|
|
236
315
|
if (!genLegacy) {
|
|
237
316
|
return { html, tags };
|
|
@@ -242,7 +321,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
242
321
|
children: safari10NoModuleFix,
|
|
243
322
|
injectTo: "body"
|
|
244
323
|
});
|
|
245
|
-
const legacyPolyfillFilename = facadeToLegacyPolyfillMap.get(
|
|
324
|
+
const legacyPolyfillFilename = facadeToLegacyPolyfillMap.get(
|
|
325
|
+
chunk.facadeModuleId
|
|
326
|
+
);
|
|
246
327
|
if (legacyPolyfillFilename) {
|
|
247
328
|
tags.push({
|
|
248
329
|
tag: "script",
|
|
@@ -250,14 +331,22 @@ function viteLegacyPlugin(options = {}) {
|
|
|
250
331
|
nomodule: true,
|
|
251
332
|
crossorigin: true,
|
|
252
333
|
id: legacyPolyfillId,
|
|
253
|
-
src: toAssetPathFromHtml(
|
|
334
|
+
src: toAssetPathFromHtml(
|
|
335
|
+
legacyPolyfillFilename,
|
|
336
|
+
chunk.facadeModuleId,
|
|
337
|
+
config
|
|
338
|
+
)
|
|
254
339
|
},
|
|
255
340
|
injectTo: "body"
|
|
256
341
|
});
|
|
257
342
|
} else if (legacyPolyfills.size) {
|
|
258
|
-
throw new Error(
|
|
343
|
+
throw new Error(
|
|
344
|
+
`No corresponding legacy polyfill chunk found for ${htmlFilename}`
|
|
345
|
+
);
|
|
259
346
|
}
|
|
260
|
-
const legacyEntryFilename = facadeToLegacyChunkMap.get(
|
|
347
|
+
const legacyEntryFilename = facadeToLegacyChunkMap.get(
|
|
348
|
+
chunk.facadeModuleId
|
|
349
|
+
);
|
|
261
350
|
if (legacyEntryFilename) {
|
|
262
351
|
tags.push({
|
|
263
352
|
tag: "script",
|
|
@@ -265,13 +354,19 @@ function viteLegacyPlugin(options = {}) {
|
|
|
265
354
|
nomodule: true,
|
|
266
355
|
crossorigin: true,
|
|
267
356
|
id: legacyEntryId,
|
|
268
|
-
"data-src": toAssetPathFromHtml(
|
|
357
|
+
"data-src": toAssetPathFromHtml(
|
|
358
|
+
legacyEntryFilename,
|
|
359
|
+
chunk.facadeModuleId,
|
|
360
|
+
config
|
|
361
|
+
)
|
|
269
362
|
},
|
|
270
363
|
children: systemJSInlineCode,
|
|
271
364
|
injectTo: "body"
|
|
272
365
|
});
|
|
273
366
|
} else {
|
|
274
|
-
throw new Error(
|
|
367
|
+
throw new Error(
|
|
368
|
+
`No corresponding legacy entry chunk found for ${htmlFilename}`
|
|
369
|
+
);
|
|
275
370
|
}
|
|
276
371
|
if (genDynamicFallback && legacyPolyfillFilename && legacyEntryFilename) {
|
|
277
372
|
tags.push({
|
|
@@ -321,7 +416,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
321
416
|
},
|
|
322
417
|
configResolved(config2) {
|
|
323
418
|
if (envInjectionFailed) {
|
|
324
|
-
config2.logger.warn(
|
|
419
|
+
config2.logger.warn(
|
|
420
|
+
`[@vitejs/plugin-legacy] import.meta.env.LEGACY was not injected due to incompatible vite version (requires vite@^2.0.0-beta.69).`
|
|
421
|
+
);
|
|
325
422
|
}
|
|
326
423
|
}
|
|
327
424
|
};
|
|
@@ -422,6 +519,13 @@ function polyfillsPlugin(imports, excludeSystemJS) {
|
|
|
422
519
|
if (id === polyfillId) {
|
|
423
520
|
return [...imports].map((i) => `import "${i}";`).join("") + (excludeSystemJS ? "" : `import "systemjs/dist/s.min.js";`);
|
|
424
521
|
}
|
|
522
|
+
},
|
|
523
|
+
renderChunk(_, __, opts) {
|
|
524
|
+
if (!excludeSystemJS) {
|
|
525
|
+
opts.__vite_skip_esbuild__ = true;
|
|
526
|
+
opts.__vite_force_terser__ = true;
|
|
527
|
+
}
|
|
528
|
+
return null;
|
|
425
529
|
}
|
|
426
530
|
};
|
|
427
531
|
}
|
|
@@ -430,7 +534,9 @@ function isLegacyChunk(chunk, options) {
|
|
|
430
534
|
}
|
|
431
535
|
function isLegacyBundle(bundle, options) {
|
|
432
536
|
if (options.format === "system") {
|
|
433
|
-
const entryChunk = Object.values(bundle).find(
|
|
537
|
+
const entryChunk = Object.values(bundle).find(
|
|
538
|
+
(output) => output.type === "chunk" && output.isEntry
|
|
539
|
+
);
|
|
434
540
|
return !!entryChunk && entryChunk.fileName.includes("-legacy");
|
|
435
541
|
}
|
|
436
542
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-legacy",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Evan You",
|
|
6
6
|
"files": [
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"dev": "unbuild --stub",
|
|
21
21
|
"build": "unbuild && pnpm run patch-cjs",
|
|
22
|
-
"patch-cjs": "
|
|
22
|
+
"patch-cjs": "tsx ../../scripts/patchCJS.ts",
|
|
23
23
|
"prepublishOnly": "npm run build"
|
|
24
24
|
},
|
|
25
25
|
"engines": {
|
|
26
|
-
"node": "
|
|
26
|
+
"node": "^14.18.0 || >=16.0.0"
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
@@ -35,18 +35,18 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@babel/standalone": "^7.18.
|
|
39
|
-
"core-js": "^3.
|
|
38
|
+
"@babel/standalone": "^7.18.12",
|
|
39
|
+
"core-js": "^3.24.1",
|
|
40
40
|
"magic-string": "^0.26.2",
|
|
41
41
|
"regenerator-runtime": "^0.13.9",
|
|
42
42
|
"systemjs": "^6.12.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"terser": "^5.4.0",
|
|
46
|
-
"vite": "^3.0.0
|
|
46
|
+
"vite": "^3.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@babel/core": "^7.18.
|
|
49
|
+
"@babel/core": "^7.18.10",
|
|
50
50
|
"vite": "workspace:*"
|
|
51
51
|
}
|
|
52
52
|
}
|