@vitejs/plugin-legacy 1.5.1 → 1.6.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/CHANGELOG.md +45 -0
- package/README.md +11 -4
- package/index.d.ts +4 -0
- package/index.js +47 -19
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
## [1.6.1](https://github.com/vitejs/vite/compare/plugin-legacy@1.6.0...plugin-legacy@1.6.1) (2021-10-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **plugin-legacy:** use terser as the default minifier ([#5168](https://github.com/vitejs/vite/issues/5168)) ([9ee7234](https://github.com/vitejs/vite/commit/9ee72343884a7d679767833f7a659bbca6b96595))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# [1.6.0](https://github.com/vitejs/vite/compare/plugin-legacy@1.5.3...plugin-legacy@1.6.0) (2021-09-29)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **deps:** update all non-major dependencies ([#4545](https://github.com/vitejs/vite/issues/4545)) ([a44fd5d](https://github.com/vitejs/vite/commit/a44fd5d38679da0be2536103e83af730cda73a95))
|
|
16
|
+
* esbuild minification and renderLegacyChunks false ([#5054](https://github.com/vitejs/vite/issues/5054)) ([ed384cf](https://github.com/vitejs/vite/commit/ed384cfeff9e3ccb0fdbb07ec91758308da66226))
|
|
17
|
+
* normalize internal plugin names ([#4976](https://github.com/vitejs/vite/issues/4976)) ([37f0b2f](https://github.com/vitejs/vite/commit/37f0b2fff74109d381513ed052a32b43655ee11d))
|
|
18
|
+
* **plugin-legacy:** fix type errors ([#4762](https://github.com/vitejs/vite/issues/4762)) ([5491143](https://github.com/vitejs/vite/commit/5491143be0b4214d2dab91076a85739d6d106481))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* **plugin-legacy:** add externalSystemJS option ([#5024](https://github.com/vitejs/vite/issues/5024)) ([60b6f55](https://github.com/vitejs/vite/commit/60b6f5595a00cbf014a30d57721081eb79436a97))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## [1.5.3](https://github.com/vitejs/vite/compare/plugin-legacy@1.5.2...plugin-legacy@1.5.3) (2021-09-07)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Bug Fixes
|
|
31
|
+
|
|
32
|
+
* **plugin-legacy:** fix regression introduced in [#4536](https://github.com/vitejs/vite/issues/4536) ([#4861](https://github.com/vitejs/vite/issues/4861)) ([fdc3212](https://github.com/vitejs/vite/commit/fdc3212474ff951e7e67810eca6cfb3ef1ed9ea2))
|
|
33
|
+
* **plugin-legacy:** skip in SSR build ([#4536](https://github.com/vitejs/vite/issues/4536)) ([1f068fc](https://github.com/vitejs/vite/commit/1f068fcec38fc07c34e75a19821064386e460907))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## [1.5.2](https://github.com/vitejs/vite/compare/plugin-legacy@1.5.1...plugin-legacy@1.5.2) (2021-09-01)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Bug Fixes
|
|
41
|
+
|
|
42
|
+
* **plugin-legacy:** avoid executing blank dynamic import ([#4767](https://github.com/vitejs/vite/issues/4767)) ([de71408](https://github.com/vitejs/vite/commit/de7140853140029a3f48600b60e700464e7662b5)), closes [#4568](https://github.com/vitejs/vite/issues/4568)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
1
46
|
## [1.5.1](https://github.com/vitejs/vite/compare/plugin-legacy@1.5.0...plugin-legacy@1.5.1) (2021-08-03)
|
|
2
47
|
|
|
3
48
|
|
package/README.md
CHANGED
|
@@ -122,6 +122,13 @@ export default {
|
|
|
122
122
|
}
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
+
### `externalSystemJS`
|
|
126
|
+
|
|
127
|
+
- **Type:** `boolean`
|
|
128
|
+
- **Default:** `false`
|
|
129
|
+
|
|
130
|
+
Defaults to `false`. Enabling this option will exclude `systemjs/dist/s.min.js` inside polyfills-legacy chunk.
|
|
131
|
+
|
|
125
132
|
## Dynamic Import
|
|
126
133
|
|
|
127
134
|
The legacy plugin offers a way to use native `import()` in the modern build while falling back to the legacy build in browsers with native ESM but without dynamic import support (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:
|
|
@@ -156,11 +163,11 @@ export default {
|
|
|
156
163
|
|
|
157
164
|
The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc), SystemJS initialization, and dynamic import fallback. If you have a strict CSP policy requirement, you will need to [add the corresponding hashes to your `script-src` list](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_inline_script):
|
|
158
165
|
|
|
159
|
-
- `MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=`
|
|
160
|
-
- `tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=`
|
|
161
|
-
- `T9h4ixy0FtNsCwAyTfBtIY6uV5ZhMeNQIlL42GAKEME=`
|
|
166
|
+
- `sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=`
|
|
167
|
+
- `sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=`
|
|
168
|
+
- `sha256-T9h4ixy0FtNsCwAyTfBtIY6uV5ZhMeNQIlL42GAKEME=`
|
|
162
169
|
|
|
163
|
-
These values can also be retrieved via
|
|
170
|
+
These values (without the `sha256-` prefix) can also be retrieved via
|
|
164
171
|
|
|
165
172
|
```js
|
|
166
173
|
const { cspHashes } = require('@vitejs/plugin-legacy')
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -20,7 +20,7 @@ const legacyEntryId = 'vite-legacy-entry'
|
|
|
20
20
|
const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`
|
|
21
21
|
const dynamicFallbackInlineCode = `!function(){try{new Function("m","return import(m)")}catch(o){console.warn("vite: loading legacy build because dynamic import is unsupported, syntax error above should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}}();`
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const forceDynamicImportUsage = `export function __vite_legacy_guard(){import('data:text/javascript,')};`
|
|
24
24
|
|
|
25
25
|
const legacyEnvVarMarker = `__VITE_IS_LEGACY__`
|
|
26
26
|
|
|
@@ -79,7 +79,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
79
79
|
* @type {import('vite').Plugin}
|
|
80
80
|
*/
|
|
81
81
|
const legacyConfigPlugin = {
|
|
82
|
-
name: 'legacy-config',
|
|
82
|
+
name: 'vite:legacy-config',
|
|
83
83
|
|
|
84
84
|
apply: 'build',
|
|
85
85
|
config(config) {
|
|
@@ -93,11 +93,19 @@ function viteLegacyPlugin(options = {}) {
|
|
|
93
93
|
* @type {import('vite').Plugin}
|
|
94
94
|
*/
|
|
95
95
|
const legacyGenerateBundlePlugin = {
|
|
96
|
-
name: 'legacy-generate-polyfill-chunk',
|
|
96
|
+
name: 'vite:legacy-generate-polyfill-chunk',
|
|
97
97
|
apply: 'build',
|
|
98
98
|
|
|
99
|
+
config() {
|
|
100
|
+
return {
|
|
101
|
+
build: {
|
|
102
|
+
minify: 'terser'
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
|
|
99
107
|
configResolved(config) {
|
|
100
|
-
if (config.build.minify === 'esbuild') {
|
|
108
|
+
if (!config.build.ssr && genLegacy && config.build.minify === 'esbuild') {
|
|
101
109
|
throw new Error(
|
|
102
110
|
`Can't use esbuild as the minifier when targeting legacy browsers ` +
|
|
103
111
|
`because esbuild minification is not legacy safe.`
|
|
@@ -106,6 +114,10 @@ function viteLegacyPlugin(options = {}) {
|
|
|
106
114
|
},
|
|
107
115
|
|
|
108
116
|
async generateBundle(opts, bundle) {
|
|
117
|
+
if (config.build.ssr) {
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
|
|
109
121
|
if (!isLegacyBundle(bundle, opts)) {
|
|
110
122
|
if (!modernPolyfills.size) {
|
|
111
123
|
return
|
|
@@ -120,7 +132,8 @@ function viteLegacyPlugin(options = {}) {
|
|
|
120
132
|
modernPolyfills,
|
|
121
133
|
bundle,
|
|
122
134
|
facadeToModernPolyfillMap,
|
|
123
|
-
config.build
|
|
135
|
+
config.build,
|
|
136
|
+
options.externalSystemJS
|
|
124
137
|
)
|
|
125
138
|
return
|
|
126
139
|
}
|
|
@@ -150,7 +163,8 @@ function viteLegacyPlugin(options = {}) {
|
|
|
150
163
|
facadeToLegacyPolyfillMap,
|
|
151
164
|
// force using terser for legacy polyfill minification, since esbuild
|
|
152
165
|
// isn't legacy-safe
|
|
153
|
-
config.build
|
|
166
|
+
config.build,
|
|
167
|
+
options.externalSystemJS
|
|
154
168
|
)
|
|
155
169
|
}
|
|
156
170
|
}
|
|
@@ -160,7 +174,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
160
174
|
* @type {import('vite').Plugin}
|
|
161
175
|
*/
|
|
162
176
|
const legacyPostPlugin = {
|
|
163
|
-
name: 'legacy-post-process',
|
|
177
|
+
name: 'vite:legacy-post-process',
|
|
164
178
|
enforce: 'post',
|
|
165
179
|
apply: 'build',
|
|
166
180
|
|
|
@@ -170,14 +184,14 @@ function viteLegacyPlugin(options = {}) {
|
|
|
170
184
|
}
|
|
171
185
|
config = _config
|
|
172
186
|
|
|
173
|
-
if (!genLegacy) {
|
|
187
|
+
if (!genLegacy || config.build.ssr) {
|
|
174
188
|
return
|
|
175
189
|
}
|
|
176
190
|
|
|
177
191
|
/**
|
|
178
192
|
* @param {string | ((chunkInfo: import('rollup').PreRenderedChunk) => string)} fileNames
|
|
179
193
|
* @param {string?} defaultFileName
|
|
180
|
-
* @returns {(chunkInfo: import('rollup').PreRenderedChunk) => string)}
|
|
194
|
+
* @returns {string | ((chunkInfo: import('rollup').PreRenderedChunk) => string)}
|
|
181
195
|
*/
|
|
182
196
|
const getLegacyOutputFileName = (
|
|
183
197
|
fileNames,
|
|
@@ -226,6 +240,10 @@ function viteLegacyPlugin(options = {}) {
|
|
|
226
240
|
},
|
|
227
241
|
|
|
228
242
|
renderChunk(raw, chunk, opts) {
|
|
243
|
+
if (config.build.ssr) {
|
|
244
|
+
return
|
|
245
|
+
}
|
|
246
|
+
|
|
229
247
|
if (!isLegacyChunk(chunk, opts)) {
|
|
230
248
|
if (
|
|
231
249
|
options.modernPolyfills &&
|
|
@@ -238,7 +256,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
238
256
|
const ms = new MagicString(raw)
|
|
239
257
|
|
|
240
258
|
if (genDynamicFallback && chunk.isEntry) {
|
|
241
|
-
ms.prepend(
|
|
259
|
+
ms.prepend(forceDynamicImportUsage)
|
|
242
260
|
}
|
|
243
261
|
|
|
244
262
|
if (raw.includes(legacyEnvVarMarker)) {
|
|
@@ -315,6 +333,7 @@ function viteLegacyPlugin(options = {}) {
|
|
|
315
333
|
},
|
|
316
334
|
|
|
317
335
|
transformIndexHtml(html, { chunk }) {
|
|
336
|
+
if (config.build.ssr) return
|
|
318
337
|
if (!chunk) return
|
|
319
338
|
if (chunk.fileName.includes('-legacy')) {
|
|
320
339
|
// The legacy bundle is built first, and its index.html isn't actually
|
|
@@ -420,6 +439,10 @@ function viteLegacyPlugin(options = {}) {
|
|
|
420
439
|
},
|
|
421
440
|
|
|
422
441
|
generateBundle(opts, bundle) {
|
|
442
|
+
if (config.build.ssr) {
|
|
443
|
+
return
|
|
444
|
+
}
|
|
445
|
+
|
|
423
446
|
if (isLegacyBundle(bundle, opts)) {
|
|
424
447
|
// avoid emitting duplicate assets
|
|
425
448
|
for (const name in bundle) {
|
|
@@ -436,14 +459,16 @@ function viteLegacyPlugin(options = {}) {
|
|
|
436
459
|
* @type {import('vite').Plugin}
|
|
437
460
|
*/
|
|
438
461
|
const legacyEnvPlugin = {
|
|
439
|
-
name: 'legacy-env',
|
|
462
|
+
name: 'vite:legacy-env',
|
|
440
463
|
|
|
441
|
-
config(
|
|
464
|
+
config(config, env) {
|
|
442
465
|
if (env) {
|
|
443
466
|
return {
|
|
444
467
|
define: {
|
|
445
468
|
'import.meta.env.LEGACY':
|
|
446
|
-
env.command === 'serve'
|
|
469
|
+
env.command === 'serve' || config.build.ssr
|
|
470
|
+
? false
|
|
471
|
+
: legacyEnvVarMarker
|
|
447
472
|
}
|
|
448
473
|
}
|
|
449
474
|
} else {
|
|
@@ -518,7 +543,8 @@ async function buildPolyfillChunk(
|
|
|
518
543
|
imports,
|
|
519
544
|
bundle,
|
|
520
545
|
facadeToChunkMap,
|
|
521
|
-
buildOptions
|
|
546
|
+
buildOptions,
|
|
547
|
+
externalSystemJS
|
|
522
548
|
) {
|
|
523
549
|
let { minify, assetsDir } = buildOptions
|
|
524
550
|
minify = minify ? 'terser' : false
|
|
@@ -527,7 +553,7 @@ async function buildPolyfillChunk(
|
|
|
527
553
|
root: __dirname,
|
|
528
554
|
configFile: false,
|
|
529
555
|
logLevel: 'error',
|
|
530
|
-
plugins: [polyfillsPlugin(imports)],
|
|
556
|
+
plugins: [polyfillsPlugin(imports, externalSystemJS)],
|
|
531
557
|
build: {
|
|
532
558
|
write: false,
|
|
533
559
|
target: false,
|
|
@@ -544,7 +570,9 @@ async function buildPolyfillChunk(
|
|
|
544
570
|
}
|
|
545
571
|
}
|
|
546
572
|
})
|
|
547
|
-
const
|
|
573
|
+
const _polyfillChunk = Array.isArray(res) ? res[0] : res
|
|
574
|
+
if (!('output' in _polyfillChunk)) return
|
|
575
|
+
const polyfillChunk = _polyfillChunk.output[0]
|
|
548
576
|
|
|
549
577
|
// associate the polyfill chunk to every entry chunk so that we can retrieve
|
|
550
578
|
// the polyfill filename in index html transform
|
|
@@ -565,9 +593,9 @@ const polyfillId = 'vite/legacy-polyfills'
|
|
|
565
593
|
* @param {Set<string>} imports
|
|
566
594
|
* @return {import('rollup').Plugin}
|
|
567
595
|
*/
|
|
568
|
-
function polyfillsPlugin(imports) {
|
|
596
|
+
function polyfillsPlugin(imports, externalSystemJS) {
|
|
569
597
|
return {
|
|
570
|
-
name: 'polyfills',
|
|
598
|
+
name: 'vite:legacy-polyfills',
|
|
571
599
|
resolveId(id) {
|
|
572
600
|
if (id === polyfillId) {
|
|
573
601
|
return id
|
|
@@ -577,7 +605,7 @@ function polyfillsPlugin(imports) {
|
|
|
577
605
|
if (id === polyfillId) {
|
|
578
606
|
return (
|
|
579
607
|
[...imports].map((i) => `import "${i}";`).join('') +
|
|
580
|
-
`import "systemjs/dist/s.min.js";`
|
|
608
|
+
(externalSystemJS ? '' : `import "systemjs/dist/s.min.js";`)
|
|
581
609
|
)
|
|
582
610
|
}
|
|
583
611
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-legacy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Evan You",
|
|
6
6
|
"files": [
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@babel/standalone": "^7.
|
|
30
|
-
"core-js": "^3.
|
|
29
|
+
"@babel/standalone": "^7.15.7",
|
|
30
|
+
"core-js": "^3.18.1",
|
|
31
31
|
"magic-string": "^0.25.7",
|
|
32
32
|
"regenerator-runtime": "^0.13.9",
|
|
33
|
-
"systemjs": "^6.10.
|
|
33
|
+
"systemjs": "^6.10.3"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"vite": "^2.0.0"
|