@vitejs/plugin-legacy 1.5.3 → 1.6.3

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 CHANGED
@@ -1,3 +1,47 @@
1
+ ## [1.6.3](https://github.com/vitejs/vite/compare/plugin-legacy@1.6.2...plugin-legacy@1.6.3) (2021-11-22)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **build:** resolve `rollupOptions.input` paths ([#5601](https://github.com/vitejs/vite/issues/5601)) ([5b6b016](https://github.com/vitejs/vite/commit/5b6b01693720290e8998b2613f0dcb2d699ee84f))
7
+
8
+
9
+
10
+ ## [1.6.2](https://github.com/vitejs/vite/compare/plugin-legacy@1.6.1...plugin-legacy@1.6.2) (2021-10-11)
11
+
12
+
13
+ ### Features
14
+
15
+ * add `build.cssTarget` option ([#5132](https://github.com/vitejs/vite/issues/5132)) ([b17444f](https://github.com/vitejs/vite/commit/b17444fd97b02bc54410c8575e7d3cb25e4058c2)), closes [#4746](https://github.com/vitejs/vite/issues/4746) [#5070](https://github.com/vitejs/vite/issues/5070) [#4930](https://github.com/vitejs/vite/issues/4930)
16
+
17
+
18
+
19
+ ## [1.6.1](https://github.com/vitejs/vite/compare/plugin-legacy@1.6.0...plugin-legacy@1.6.1) (2021-10-05)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * **plugin-legacy:** use terser as the default minifier ([#5168](https://github.com/vitejs/vite/issues/5168)) ([9ee7234](https://github.com/vitejs/vite/commit/9ee72343884a7d679767833f7a659bbca6b96595))
25
+
26
+
27
+
28
+ # [1.6.0](https://github.com/vitejs/vite/compare/plugin-legacy@1.5.3...plugin-legacy@1.6.0) (2021-09-29)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * **deps:** update all non-major dependencies ([#4545](https://github.com/vitejs/vite/issues/4545)) ([a44fd5d](https://github.com/vitejs/vite/commit/a44fd5d38679da0be2536103e83af730cda73a95))
34
+ * esbuild minification and renderLegacyChunks false ([#5054](https://github.com/vitejs/vite/issues/5054)) ([ed384cf](https://github.com/vitejs/vite/commit/ed384cfeff9e3ccb0fdbb07ec91758308da66226))
35
+ * normalize internal plugin names ([#4976](https://github.com/vitejs/vite/issues/4976)) ([37f0b2f](https://github.com/vitejs/vite/commit/37f0b2fff74109d381513ed052a32b43655ee11d))
36
+ * **plugin-legacy:** fix type errors ([#4762](https://github.com/vitejs/vite/issues/4762)) ([5491143](https://github.com/vitejs/vite/commit/5491143be0b4214d2dab91076a85739d6d106481))
37
+
38
+
39
+ ### Features
40
+
41
+ * **plugin-legacy:** add externalSystemJS option ([#5024](https://github.com/vitejs/vite/issues/5024)) ([60b6f55](https://github.com/vitejs/vite/commit/60b6f5595a00cbf014a30d57721081eb79436a97))
42
+
43
+
44
+
1
45
  ## [1.5.3](https://github.com/vitejs/vite/compare/plugin-legacy@1.5.2...plugin-legacy@1.5.3) (2021-09-07)
2
46
 
3
47
 
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:
package/index.d.ts CHANGED
@@ -22,6 +22,10 @@ export interface Options {
22
22
  * default: true
23
23
  */
24
24
  renderLegacyChunks?: boolean
25
+ /**
26
+ * default: false
27
+ */
28
+ externalSystemJS?: boolean
25
29
  }
26
30
 
27
31
  declare function createPlugin(options?: Options): Plugin
package/index.js CHANGED
@@ -79,13 +79,22 @@ 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) {
86
86
  if (!config.build) {
87
87
  config.build = {}
88
88
  }
89
+
90
+ if (!config.build.cssTarget) {
91
+ // Hint for esbuild that we are targeting legacy browsers when minifying CSS.
92
+ // Full CSS compat table available at https://github.com/evanw/esbuild/blob/78e04680228cf989bdd7d471e02bbc2c8d345dc9/internal/compat/css_table.go
93
+ // But note that only the `HexRGBA` feature affects the minify outcome.
94
+ // HSL & rebeccapurple values will be minified away regardless the target.
95
+ // So targeting `chrome61` suffices to fix the compatiblity issue.
96
+ config.build.cssTarget = 'chrome61'
97
+ }
89
98
  }
90
99
  }
91
100
 
@@ -93,11 +102,19 @@ function viteLegacyPlugin(options = {}) {
93
102
  * @type {import('vite').Plugin}
94
103
  */
95
104
  const legacyGenerateBundlePlugin = {
96
- name: 'legacy-generate-polyfill-chunk',
105
+ name: 'vite:legacy-generate-polyfill-chunk',
97
106
  apply: 'build',
98
107
 
108
+ config() {
109
+ return {
110
+ build: {
111
+ minify: 'terser'
112
+ }
113
+ }
114
+ },
115
+
99
116
  configResolved(config) {
100
- if (!config.build.ssr && config.build.minify === 'esbuild') {
117
+ if (!config.build.ssr && genLegacy && config.build.minify === 'esbuild') {
101
118
  throw new Error(
102
119
  `Can't use esbuild as the minifier when targeting legacy browsers ` +
103
120
  `because esbuild minification is not legacy safe.`
@@ -124,7 +141,8 @@ function viteLegacyPlugin(options = {}) {
124
141
  modernPolyfills,
125
142
  bundle,
126
143
  facadeToModernPolyfillMap,
127
- config.build
144
+ config.build,
145
+ options.externalSystemJS
128
146
  )
129
147
  return
130
148
  }
@@ -154,7 +172,8 @@ function viteLegacyPlugin(options = {}) {
154
172
  facadeToLegacyPolyfillMap,
155
173
  // force using terser for legacy polyfill minification, since esbuild
156
174
  // isn't legacy-safe
157
- config.build
175
+ config.build,
176
+ options.externalSystemJS
158
177
  )
159
178
  }
160
179
  }
@@ -164,7 +183,7 @@ function viteLegacyPlugin(options = {}) {
164
183
  * @type {import('vite').Plugin}
165
184
  */
166
185
  const legacyPostPlugin = {
167
- name: 'legacy-post-process',
186
+ name: 'vite:legacy-post-process',
168
187
  enforce: 'post',
169
188
  apply: 'build',
170
189
 
@@ -181,7 +200,7 @@ function viteLegacyPlugin(options = {}) {
181
200
  /**
182
201
  * @param {string | ((chunkInfo: import('rollup').PreRenderedChunk) => string)} fileNames
183
202
  * @param {string?} defaultFileName
184
- * @returns {(chunkInfo: import('rollup').PreRenderedChunk) => string)}
203
+ * @returns {string | ((chunkInfo: import('rollup').PreRenderedChunk) => string)}
185
204
  */
186
205
  const getLegacyOutputFileName = (
187
206
  fileNames,
@@ -449,7 +468,7 @@ function viteLegacyPlugin(options = {}) {
449
468
  * @type {import('vite').Plugin}
450
469
  */
451
470
  const legacyEnvPlugin = {
452
- name: 'legacy-env',
471
+ name: 'vite:legacy-env',
453
472
 
454
473
  config(config, env) {
455
474
  if (env) {
@@ -533,7 +552,8 @@ async function buildPolyfillChunk(
533
552
  imports,
534
553
  bundle,
535
554
  facadeToChunkMap,
536
- buildOptions
555
+ buildOptions,
556
+ externalSystemJS
537
557
  ) {
538
558
  let { minify, assetsDir } = buildOptions
539
559
  minify = minify ? 'terser' : false
@@ -542,7 +562,7 @@ async function buildPolyfillChunk(
542
562
  root: __dirname,
543
563
  configFile: false,
544
564
  logLevel: 'error',
545
- plugins: [polyfillsPlugin(imports)],
565
+ plugins: [polyfillsPlugin(imports, externalSystemJS)],
546
566
  build: {
547
567
  write: false,
548
568
  target: false,
@@ -559,7 +579,9 @@ async function buildPolyfillChunk(
559
579
  }
560
580
  }
561
581
  })
562
- const polyfillChunk = (Array.isArray(res) ? res[0] : res).output[0]
582
+ const _polyfillChunk = Array.isArray(res) ? res[0] : res
583
+ if (!('output' in _polyfillChunk)) return
584
+ const polyfillChunk = _polyfillChunk.output[0]
563
585
 
564
586
  // associate the polyfill chunk to every entry chunk so that we can retrieve
565
587
  // the polyfill filename in index html transform
@@ -574,15 +596,15 @@ async function buildPolyfillChunk(
574
596
  bundle[polyfillChunk.name] = polyfillChunk
575
597
  }
576
598
 
577
- const polyfillId = 'vite/legacy-polyfills'
599
+ const polyfillId = '\0vite/legacy-polyfills'
578
600
 
579
601
  /**
580
602
  * @param {Set<string>} imports
581
603
  * @return {import('rollup').Plugin}
582
604
  */
583
- function polyfillsPlugin(imports) {
605
+ function polyfillsPlugin(imports, externalSystemJS) {
584
606
  return {
585
- name: 'polyfills',
607
+ name: 'vite:legacy-polyfills',
586
608
  resolveId(id) {
587
609
  if (id === polyfillId) {
588
610
  return id
@@ -592,7 +614,7 @@ function polyfillsPlugin(imports) {
592
614
  if (id === polyfillId) {
593
615
  return (
594
616
  [...imports].map((i) => `import "${i}";`).join('') +
595
- `import "systemjs/dist/s.min.js";`
617
+ (externalSystemJS ? '' : `import "systemjs/dist/s.min.js";`)
596
618
  )
597
619
  }
598
620
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-legacy",
3
- "version": "1.5.3",
3
+ "version": "1.6.3",
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.14.9",
30
- "core-js": "^3.16.0",
29
+ "@babel/standalone": "^7.16.4",
30
+ "core-js": "^3.19.1",
31
31
  "magic-string": "^0.25.7",
32
32
  "regenerator-runtime": "^0.13.9",
33
- "systemjs": "^6.10.2"
33
+ "systemjs": "^6.11.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "vite": "^2.0.0"