@vitejs/plugin-legacy 8.0.0-beta.2 → 8.0.0-beta.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @vitejs/plugin-legacy [![npm](https://img.shields.io/npm/v/@vitejs/plugin-legacy.svg)](https://npmjs.com/package/@vitejs/plugin-legacy)
2
2
 
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.
3
+ Vite's minimum browser support target is [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
 
@@ -135,7 +135,7 @@ npm add -D terser
135
135
 
136
136
  ## Browsers that supports ESM but does not support widely-available features
137
137
 
138
- The legacy plugin offers a way to use widely-available features natively in the modern build, while falling back to the legacy build in browsers with native ESM but without those features supported (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:
138
+ The legacy plugin offers a way to use widely-available features natively in the modern build, while falling back to the legacy build in browsers with native ESM but without those features supported (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:
139
139
 
140
140
  - Modern bundle is downloaded in all ESM browsers
141
141
  - Modern bundle throws `SyntaxError` in browsers without those features support
package/dist/index.js CHANGED
@@ -155,6 +155,7 @@ function toAssetPathFromHtml(filename, htmlPath, config) {
155
155
  return toOutputFilePathInHtml(filename, "asset", htmlPath, "html", config, toRelative);
156
156
  }
157
157
  const legacyEnvVarMarker = `__VITE_IS_LEGACY__`;
158
+ const modernEnvVarMarker = `__VITE_IS_MODERN__`;
158
159
  const _require = createRequire(import.meta.url);
159
160
  const nonLeadingHashInFileNameRE = /[^/]+\[hash(?::\d+)?\]/;
160
161
  const prefixedHashInFileNameRE = /\W?\[hash(?::\d+)?\]/;
@@ -340,6 +341,7 @@ function viteLegacyPlugin(options = {}) {
340
341
  presets: [[() => ({ plugins: [
341
342
  recordAndRemovePolyfillBabelPlugin(polyfillsDiscovered.legacy),
342
343
  replaceLegacyEnvBabelPlugin(),
344
+ replaceModernEnvBabelPlugin(),
343
345
  wrapIIFEBabelPlugin()
344
346
  ] })], [(await import("@babel/preset-env")).default, {
345
347
  bugfixes: true,
@@ -580,6 +582,14 @@ function replaceLegacyEnvBabelPlugin() {
580
582
  } }
581
583
  });
582
584
  }
585
+ function replaceModernEnvBabelPlugin() {
586
+ return ({ types: t }) => ({
587
+ name: "vite-replace-env-modern",
588
+ visitor: { Identifier(path) {
589
+ if (path.node.name === modernEnvVarMarker) path.replaceWith(t.booleanLiteral(false));
590
+ } }
591
+ });
592
+ }
583
593
  function wrapIIFEBabelPlugin() {
584
594
  return ({ types: t, template }) => {
585
595
  const buildIIFE = template(";(function(){%%body%%})();");
@@ -600,7 +610,6 @@ const cspHashes = [
600
610
  detectModernBrowserCode,
601
611
  dynamicFallbackInlineCode
602
612
  ].map((i) => crypto.hash("sha256", i, "base64"));
603
- var src_default = viteLegacyPlugin;
604
613
  function viteLegacyPluginCjs(options) {
605
614
  return viteLegacyPlugin.call(this, options);
606
615
  }
@@ -611,4 +620,4 @@ Object.assign(viteLegacyPluginCjs, {
611
620
  });
612
621
 
613
622
  //#endregion
614
- export { cspHashes, src_default as default, detectPolyfills, viteLegacyPluginCjs as "module.exports" };
623
+ export { cspHashes, viteLegacyPlugin as default, detectPolyfills, viteLegacyPluginCjs as "module.exports" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-legacy",
3
- "version": "8.0.0-beta.2",
3
+ "version": "8.0.0-beta.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -48,8 +48,8 @@
48
48
  "devDependencies": {
49
49
  "acorn": "^8.15.0",
50
50
  "picocolors": "^1.1.1",
51
- "tsdown": "^0.20.1",
52
- "vite": "8.0.0-beta.12"
51
+ "tsdown": "^0.20.3",
52
+ "vite": "8.0.0-beta.14"
53
53
  },
54
54
  "compatiblePackages": {
55
55
  "schemaVersion": 1,