@vitejs/plugin-legacy 2.0.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/dist/index.cjs +103 -22
- package/dist/index.mjs +103 -22
- package/package.json +5 -5
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/dist/index.cjs
CHANGED
|
@@ -33,7 +33,9 @@ function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRela
|
|
|
33
33
|
});
|
|
34
34
|
if (typeof result === "object") {
|
|
35
35
|
if (result.runtime) {
|
|
36
|
-
throw new Error(
|
|
36
|
+
throw new Error(
|
|
37
|
+
`{ runtime: "${result.runtime}" } is not supported for assets in ${hostType} files: ${filename}`
|
|
38
|
+
);
|
|
37
39
|
}
|
|
38
40
|
if (typeof result.relative === "boolean") {
|
|
39
41
|
relative = result.relative;
|
|
@@ -49,12 +51,22 @@ function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRela
|
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
function getBaseInHTML(urlRelativePath, config) {
|
|
52
|
-
return config.base === "./" || config.base === "" ? path__default.posix.join(
|
|
54
|
+
return config.base === "./" || config.base === "" ? path__default.posix.join(
|
|
55
|
+
path__default.posix.relative(urlRelativePath, "").slice(0, -2),
|
|
56
|
+
"./"
|
|
57
|
+
) : config.base;
|
|
53
58
|
}
|
|
54
59
|
function toAssetPathFromHtml(filename, htmlPath, config) {
|
|
55
60
|
const relativeUrlPath = vite.normalizePath(path__default.relative(config.root, htmlPath));
|
|
56
61
|
const toRelative = (filename2, hostId) => getBaseInHTML(relativeUrlPath, config) + filename2;
|
|
57
|
-
return toOutputFilePathInHtml(
|
|
62
|
+
return toOutputFilePathInHtml(
|
|
63
|
+
filename,
|
|
64
|
+
"asset",
|
|
65
|
+
htmlPath,
|
|
66
|
+
"html",
|
|
67
|
+
config,
|
|
68
|
+
toRelative
|
|
69
|
+
);
|
|
58
70
|
}
|
|
59
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()}}();`;
|
|
60
72
|
const legacyPolyfillId = "vite-legacy-polyfill";
|
|
@@ -80,7 +92,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
80
92
|
const legacyPolyfills = /* @__PURE__ */ new Set();
|
|
81
93
|
if (Array.isArray(options.modernPolyfills)) {
|
|
82
94
|
options.modernPolyfills.forEach((i) => {
|
|
83
|
-
modernPolyfills.add(
|
|
95
|
+
modernPolyfills.add(
|
|
96
|
+
i.includes("/") ? `core-js/${i}` : `core-js/modules/${i}.js`
|
|
97
|
+
);
|
|
84
98
|
});
|
|
85
99
|
}
|
|
86
100
|
if (Array.isArray(options.polyfills)) {
|
|
@@ -88,7 +102,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
88
102
|
if (i.startsWith(`regenerator`)) {
|
|
89
103
|
legacyPolyfills.add(`regenerator-runtime/runtime.js`);
|
|
90
104
|
} else {
|
|
91
|
-
legacyPolyfills.add(
|
|
105
|
+
legacyPolyfills.add(
|
|
106
|
+
i.includes("/") ? `core-js/${i}` : `core-js/modules/${i}.js`
|
|
107
|
+
);
|
|
92
108
|
}
|
|
93
109
|
});
|
|
94
110
|
}
|
|
@@ -120,17 +136,43 @@ function viteLegacyPlugin(options = {}) {
|
|
|
120
136
|
if (!modernPolyfills.size) {
|
|
121
137
|
return;
|
|
122
138
|
}
|
|
123
|
-
isDebug && console.log(
|
|
124
|
-
|
|
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
|
+
);
|
|
125
152
|
return;
|
|
126
153
|
}
|
|
127
154
|
if (!genLegacy) {
|
|
128
155
|
return;
|
|
129
156
|
}
|
|
130
157
|
if (legacyPolyfills.size || genDynamicFallback) {
|
|
131
|
-
await detectPolyfills(
|
|
132
|
-
|
|
133
|
-
|
|
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
|
+
);
|
|
134
176
|
}
|
|
135
177
|
}
|
|
136
178
|
};
|
|
@@ -192,7 +234,11 @@ function viteLegacyPlugin(options = {}) {
|
|
|
192
234
|
const re = new RegExp(legacyEnvVarMarker, "g");
|
|
193
235
|
let match;
|
|
194
236
|
while (match = re.exec(raw)) {
|
|
195
|
-
ms.overwrite(
|
|
237
|
+
ms.overwrite(
|
|
238
|
+
match.index,
|
|
239
|
+
match.index + legacyEnvVarMarker.length,
|
|
240
|
+
`false`
|
|
241
|
+
);
|
|
196
242
|
}
|
|
197
243
|
}
|
|
198
244
|
if (config.build.sourcemap) {
|
|
@@ -254,18 +300,26 @@ function viteLegacyPlugin(options = {}) {
|
|
|
254
300
|
}
|
|
255
301
|
const tags = [];
|
|
256
302
|
const htmlFilename = chunk.facadeModuleId?.replace(/\?.*$/, "");
|
|
257
|
-
const modernPolyfillFilename = facadeToModernPolyfillMap.get(
|
|
303
|
+
const modernPolyfillFilename = facadeToModernPolyfillMap.get(
|
|
304
|
+
chunk.facadeModuleId
|
|
305
|
+
);
|
|
258
306
|
if (modernPolyfillFilename) {
|
|
259
307
|
tags.push({
|
|
260
308
|
tag: "script",
|
|
261
309
|
attrs: {
|
|
262
310
|
type: "module",
|
|
263
311
|
crossorigin: true,
|
|
264
|
-
src: toAssetPathFromHtml(
|
|
312
|
+
src: toAssetPathFromHtml(
|
|
313
|
+
modernPolyfillFilename,
|
|
314
|
+
chunk.facadeModuleId,
|
|
315
|
+
config
|
|
316
|
+
)
|
|
265
317
|
}
|
|
266
318
|
});
|
|
267
319
|
} else if (modernPolyfills.size) {
|
|
268
|
-
throw new Error(
|
|
320
|
+
throw new Error(
|
|
321
|
+
`No corresponding modern polyfill chunk found for ${htmlFilename}`
|
|
322
|
+
);
|
|
269
323
|
}
|
|
270
324
|
if (!genLegacy) {
|
|
271
325
|
return { html, tags };
|
|
@@ -276,7 +330,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
276
330
|
children: safari10NoModuleFix,
|
|
277
331
|
injectTo: "body"
|
|
278
332
|
});
|
|
279
|
-
const legacyPolyfillFilename = facadeToLegacyPolyfillMap.get(
|
|
333
|
+
const legacyPolyfillFilename = facadeToLegacyPolyfillMap.get(
|
|
334
|
+
chunk.facadeModuleId
|
|
335
|
+
);
|
|
280
336
|
if (legacyPolyfillFilename) {
|
|
281
337
|
tags.push({
|
|
282
338
|
tag: "script",
|
|
@@ -284,14 +340,22 @@ function viteLegacyPlugin(options = {}) {
|
|
|
284
340
|
nomodule: true,
|
|
285
341
|
crossorigin: true,
|
|
286
342
|
id: legacyPolyfillId,
|
|
287
|
-
src: toAssetPathFromHtml(
|
|
343
|
+
src: toAssetPathFromHtml(
|
|
344
|
+
legacyPolyfillFilename,
|
|
345
|
+
chunk.facadeModuleId,
|
|
346
|
+
config
|
|
347
|
+
)
|
|
288
348
|
},
|
|
289
349
|
injectTo: "body"
|
|
290
350
|
});
|
|
291
351
|
} else if (legacyPolyfills.size) {
|
|
292
|
-
throw new Error(
|
|
352
|
+
throw new Error(
|
|
353
|
+
`No corresponding legacy polyfill chunk found for ${htmlFilename}`
|
|
354
|
+
);
|
|
293
355
|
}
|
|
294
|
-
const legacyEntryFilename = facadeToLegacyChunkMap.get(
|
|
356
|
+
const legacyEntryFilename = facadeToLegacyChunkMap.get(
|
|
357
|
+
chunk.facadeModuleId
|
|
358
|
+
);
|
|
295
359
|
if (legacyEntryFilename) {
|
|
296
360
|
tags.push({
|
|
297
361
|
tag: "script",
|
|
@@ -299,13 +363,19 @@ function viteLegacyPlugin(options = {}) {
|
|
|
299
363
|
nomodule: true,
|
|
300
364
|
crossorigin: true,
|
|
301
365
|
id: legacyEntryId,
|
|
302
|
-
"data-src": toAssetPathFromHtml(
|
|
366
|
+
"data-src": toAssetPathFromHtml(
|
|
367
|
+
legacyEntryFilename,
|
|
368
|
+
chunk.facadeModuleId,
|
|
369
|
+
config
|
|
370
|
+
)
|
|
303
371
|
},
|
|
304
372
|
children: systemJSInlineCode,
|
|
305
373
|
injectTo: "body"
|
|
306
374
|
});
|
|
307
375
|
} else {
|
|
308
|
-
throw new Error(
|
|
376
|
+
throw new Error(
|
|
377
|
+
`No corresponding legacy entry chunk found for ${htmlFilename}`
|
|
378
|
+
);
|
|
309
379
|
}
|
|
310
380
|
if (genDynamicFallback && legacyPolyfillFilename && legacyEntryFilename) {
|
|
311
381
|
tags.push({
|
|
@@ -355,7 +425,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
355
425
|
},
|
|
356
426
|
configResolved(config2) {
|
|
357
427
|
if (envInjectionFailed) {
|
|
358
|
-
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
|
+
);
|
|
359
431
|
}
|
|
360
432
|
}
|
|
361
433
|
};
|
|
@@ -456,6 +528,13 @@ function polyfillsPlugin(imports, excludeSystemJS) {
|
|
|
456
528
|
if (id === polyfillId) {
|
|
457
529
|
return [...imports].map((i) => `import "${i}";`).join("") + (excludeSystemJS ? "" : `import "systemjs/dist/s.min.js";`);
|
|
458
530
|
}
|
|
531
|
+
},
|
|
532
|
+
renderChunk(_, __, opts) {
|
|
533
|
+
if (!excludeSystemJS) {
|
|
534
|
+
opts.__vite_skip_esbuild__ = true;
|
|
535
|
+
opts.__vite_force_terser__ = true;
|
|
536
|
+
}
|
|
537
|
+
return null;
|
|
459
538
|
}
|
|
460
539
|
};
|
|
461
540
|
}
|
|
@@ -464,7 +543,9 @@ function isLegacyChunk(chunk, options) {
|
|
|
464
543
|
}
|
|
465
544
|
function isLegacyBundle(bundle, options) {
|
|
466
545
|
if (options.format === "system") {
|
|
467
|
-
const entryChunk = Object.values(bundle).find(
|
|
546
|
+
const entryChunk = Object.values(bundle).find(
|
|
547
|
+
(output) => output.type === "chunk" && output.isEntry
|
|
548
|
+
);
|
|
468
549
|
return !!entryChunk && entryChunk.fileName.includes("-legacy");
|
|
469
550
|
}
|
|
470
551
|
return false;
|
package/dist/index.mjs
CHANGED
|
@@ -24,7 +24,9 @@ function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRela
|
|
|
24
24
|
});
|
|
25
25
|
if (typeof result === "object") {
|
|
26
26
|
if (result.runtime) {
|
|
27
|
-
throw new Error(
|
|
27
|
+
throw new Error(
|
|
28
|
+
`{ runtime: "${result.runtime}" } is not supported for assets in ${hostType} files: ${filename}`
|
|
29
|
+
);
|
|
28
30
|
}
|
|
29
31
|
if (typeof result.relative === "boolean") {
|
|
30
32
|
relative = result.relative;
|
|
@@ -40,12 +42,22 @@ function toOutputFilePathInHtml(filename, type, hostId, hostType, config, toRela
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
function getBaseInHTML(urlRelativePath, config) {
|
|
43
|
-
return config.base === "./" || config.base === "" ? path.posix.join(
|
|
45
|
+
return config.base === "./" || config.base === "" ? path.posix.join(
|
|
46
|
+
path.posix.relative(urlRelativePath, "").slice(0, -2),
|
|
47
|
+
"./"
|
|
48
|
+
) : config.base;
|
|
44
49
|
}
|
|
45
50
|
function toAssetPathFromHtml(filename, htmlPath, config) {
|
|
46
51
|
const relativeUrlPath = normalizePath(path.relative(config.root, htmlPath));
|
|
47
52
|
const toRelative = (filename2, hostId) => getBaseInHTML(relativeUrlPath, config) + filename2;
|
|
48
|
-
return toOutputFilePathInHtml(
|
|
53
|
+
return toOutputFilePathInHtml(
|
|
54
|
+
filename,
|
|
55
|
+
"asset",
|
|
56
|
+
htmlPath,
|
|
57
|
+
"html",
|
|
58
|
+
config,
|
|
59
|
+
toRelative
|
|
60
|
+
);
|
|
49
61
|
}
|
|
50
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()}}();`;
|
|
51
63
|
const legacyPolyfillId = "vite-legacy-polyfill";
|
|
@@ -71,7 +83,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
71
83
|
const legacyPolyfills = /* @__PURE__ */ new Set();
|
|
72
84
|
if (Array.isArray(options.modernPolyfills)) {
|
|
73
85
|
options.modernPolyfills.forEach((i) => {
|
|
74
|
-
modernPolyfills.add(
|
|
86
|
+
modernPolyfills.add(
|
|
87
|
+
i.includes("/") ? `core-js/${i}` : `core-js/modules/${i}.js`
|
|
88
|
+
);
|
|
75
89
|
});
|
|
76
90
|
}
|
|
77
91
|
if (Array.isArray(options.polyfills)) {
|
|
@@ -79,7 +93,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
79
93
|
if (i.startsWith(`regenerator`)) {
|
|
80
94
|
legacyPolyfills.add(`regenerator-runtime/runtime.js`);
|
|
81
95
|
} else {
|
|
82
|
-
legacyPolyfills.add(
|
|
96
|
+
legacyPolyfills.add(
|
|
97
|
+
i.includes("/") ? `core-js/${i}` : `core-js/modules/${i}.js`
|
|
98
|
+
);
|
|
83
99
|
}
|
|
84
100
|
});
|
|
85
101
|
}
|
|
@@ -111,17 +127,43 @@ function viteLegacyPlugin(options = {}) {
|
|
|
111
127
|
if (!modernPolyfills.size) {
|
|
112
128
|
return;
|
|
113
129
|
}
|
|
114
|
-
isDebug && console.log(
|
|
115
|
-
|
|
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
|
+
);
|
|
116
143
|
return;
|
|
117
144
|
}
|
|
118
145
|
if (!genLegacy) {
|
|
119
146
|
return;
|
|
120
147
|
}
|
|
121
148
|
if (legacyPolyfills.size || genDynamicFallback) {
|
|
122
|
-
await detectPolyfills(
|
|
123
|
-
|
|
124
|
-
|
|
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
|
+
);
|
|
125
167
|
}
|
|
126
168
|
}
|
|
127
169
|
};
|
|
@@ -183,7 +225,11 @@ function viteLegacyPlugin(options = {}) {
|
|
|
183
225
|
const re = new RegExp(legacyEnvVarMarker, "g");
|
|
184
226
|
let match;
|
|
185
227
|
while (match = re.exec(raw)) {
|
|
186
|
-
ms.overwrite(
|
|
228
|
+
ms.overwrite(
|
|
229
|
+
match.index,
|
|
230
|
+
match.index + legacyEnvVarMarker.length,
|
|
231
|
+
`false`
|
|
232
|
+
);
|
|
187
233
|
}
|
|
188
234
|
}
|
|
189
235
|
if (config.build.sourcemap) {
|
|
@@ -245,18 +291,26 @@ function viteLegacyPlugin(options = {}) {
|
|
|
245
291
|
}
|
|
246
292
|
const tags = [];
|
|
247
293
|
const htmlFilename = chunk.facadeModuleId?.replace(/\?.*$/, "");
|
|
248
|
-
const modernPolyfillFilename = facadeToModernPolyfillMap.get(
|
|
294
|
+
const modernPolyfillFilename = facadeToModernPolyfillMap.get(
|
|
295
|
+
chunk.facadeModuleId
|
|
296
|
+
);
|
|
249
297
|
if (modernPolyfillFilename) {
|
|
250
298
|
tags.push({
|
|
251
299
|
tag: "script",
|
|
252
300
|
attrs: {
|
|
253
301
|
type: "module",
|
|
254
302
|
crossorigin: true,
|
|
255
|
-
src: toAssetPathFromHtml(
|
|
303
|
+
src: toAssetPathFromHtml(
|
|
304
|
+
modernPolyfillFilename,
|
|
305
|
+
chunk.facadeModuleId,
|
|
306
|
+
config
|
|
307
|
+
)
|
|
256
308
|
}
|
|
257
309
|
});
|
|
258
310
|
} else if (modernPolyfills.size) {
|
|
259
|
-
throw new Error(
|
|
311
|
+
throw new Error(
|
|
312
|
+
`No corresponding modern polyfill chunk found for ${htmlFilename}`
|
|
313
|
+
);
|
|
260
314
|
}
|
|
261
315
|
if (!genLegacy) {
|
|
262
316
|
return { html, tags };
|
|
@@ -267,7 +321,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
267
321
|
children: safari10NoModuleFix,
|
|
268
322
|
injectTo: "body"
|
|
269
323
|
});
|
|
270
|
-
const legacyPolyfillFilename = facadeToLegacyPolyfillMap.get(
|
|
324
|
+
const legacyPolyfillFilename = facadeToLegacyPolyfillMap.get(
|
|
325
|
+
chunk.facadeModuleId
|
|
326
|
+
);
|
|
271
327
|
if (legacyPolyfillFilename) {
|
|
272
328
|
tags.push({
|
|
273
329
|
tag: "script",
|
|
@@ -275,14 +331,22 @@ function viteLegacyPlugin(options = {}) {
|
|
|
275
331
|
nomodule: true,
|
|
276
332
|
crossorigin: true,
|
|
277
333
|
id: legacyPolyfillId,
|
|
278
|
-
src: toAssetPathFromHtml(
|
|
334
|
+
src: toAssetPathFromHtml(
|
|
335
|
+
legacyPolyfillFilename,
|
|
336
|
+
chunk.facadeModuleId,
|
|
337
|
+
config
|
|
338
|
+
)
|
|
279
339
|
},
|
|
280
340
|
injectTo: "body"
|
|
281
341
|
});
|
|
282
342
|
} else if (legacyPolyfills.size) {
|
|
283
|
-
throw new Error(
|
|
343
|
+
throw new Error(
|
|
344
|
+
`No corresponding legacy polyfill chunk found for ${htmlFilename}`
|
|
345
|
+
);
|
|
284
346
|
}
|
|
285
|
-
const legacyEntryFilename = facadeToLegacyChunkMap.get(
|
|
347
|
+
const legacyEntryFilename = facadeToLegacyChunkMap.get(
|
|
348
|
+
chunk.facadeModuleId
|
|
349
|
+
);
|
|
286
350
|
if (legacyEntryFilename) {
|
|
287
351
|
tags.push({
|
|
288
352
|
tag: "script",
|
|
@@ -290,13 +354,19 @@ function viteLegacyPlugin(options = {}) {
|
|
|
290
354
|
nomodule: true,
|
|
291
355
|
crossorigin: true,
|
|
292
356
|
id: legacyEntryId,
|
|
293
|
-
"data-src": toAssetPathFromHtml(
|
|
357
|
+
"data-src": toAssetPathFromHtml(
|
|
358
|
+
legacyEntryFilename,
|
|
359
|
+
chunk.facadeModuleId,
|
|
360
|
+
config
|
|
361
|
+
)
|
|
294
362
|
},
|
|
295
363
|
children: systemJSInlineCode,
|
|
296
364
|
injectTo: "body"
|
|
297
365
|
});
|
|
298
366
|
} else {
|
|
299
|
-
throw new Error(
|
|
367
|
+
throw new Error(
|
|
368
|
+
`No corresponding legacy entry chunk found for ${htmlFilename}`
|
|
369
|
+
);
|
|
300
370
|
}
|
|
301
371
|
if (genDynamicFallback && legacyPolyfillFilename && legacyEntryFilename) {
|
|
302
372
|
tags.push({
|
|
@@ -346,7 +416,9 @@ function viteLegacyPlugin(options = {}) {
|
|
|
346
416
|
},
|
|
347
417
|
configResolved(config2) {
|
|
348
418
|
if (envInjectionFailed) {
|
|
349
|
-
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
|
+
);
|
|
350
422
|
}
|
|
351
423
|
}
|
|
352
424
|
};
|
|
@@ -447,6 +519,13 @@ function polyfillsPlugin(imports, excludeSystemJS) {
|
|
|
447
519
|
if (id === polyfillId) {
|
|
448
520
|
return [...imports].map((i) => `import "${i}";`).join("") + (excludeSystemJS ? "" : `import "systemjs/dist/s.min.js";`);
|
|
449
521
|
}
|
|
522
|
+
},
|
|
523
|
+
renderChunk(_, __, opts) {
|
|
524
|
+
if (!excludeSystemJS) {
|
|
525
|
+
opts.__vite_skip_esbuild__ = true;
|
|
526
|
+
opts.__vite_force_terser__ = true;
|
|
527
|
+
}
|
|
528
|
+
return null;
|
|
450
529
|
}
|
|
451
530
|
};
|
|
452
531
|
}
|
|
@@ -455,7 +534,9 @@ function isLegacyChunk(chunk, options) {
|
|
|
455
534
|
}
|
|
456
535
|
function isLegacyBundle(bundle, options) {
|
|
457
536
|
if (options.format === "system") {
|
|
458
|
-
const entryChunk = Object.values(bundle).find(
|
|
537
|
+
const entryChunk = Object.values(bundle).find(
|
|
538
|
+
(output) => output.type === "chunk" && output.isEntry
|
|
539
|
+
);
|
|
459
540
|
return !!entryChunk && entryChunk.fileName.includes("-legacy");
|
|
460
541
|
}
|
|
461
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": [
|
|
@@ -23,7 +23,7 @@
|
|
|
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,8 +35,8 @@
|
|
|
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"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
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
|
}
|