Skip to content

Commit 97569ef

Browse files
authored
docs: rephrase browser range and features relation (#19286)
1 parent 2bea7ce commit 97569ef

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

docs/guide/build.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ When it is time to deploy your app for production, simply run the `vite build` c
44

55
## Browser Compatibility
66

7-
By default, the production bundle assumes support for modern JavaScript, including [native ES Modules](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). The default browser support range is:
7+
By default, the production bundle assumes support for modern JavaScript, such as [native ES Modules](https://caniuse.com/es6-module), [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import), [`import.meta`](https://caniuse.com/mdn-javascript_operators_import_meta), [nullish coalescing](https://caniuse.com/mdn-javascript_operators_nullish_coalescing), and [BigInt](https://caniuse.com/bigint). The default browser support range is:
8+
9+
<!-- Search for the `ESBUILD_MODULES_TARGET` constant for more information -->
810

911
- Chrome >=87
1012
- Firefox >=78
1113
- Safari >=14
1214
- Edge >=88
1315

14-
You can specify custom targets via the [`build.target` config option](/config/build-options.md#build-target), where the lowest target is `es2015`. If a lower target is set, Vite will still require these minimum browser support ranges as it relies on [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import) and [`import.meta`](https://caniuse.com/mdn-javascript_operators_import_meta):
16+
You can specify custom targets via the [`build.target` config option](/config/build-options.md#build-target), where the lowest target is `es2015`. If a lower target is set, Vite will still require these minimum browser support ranges as it relies on [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import), and [`import.meta`](https://caniuse.com/mdn-javascript_operators_import_meta):
17+
18+
<!-- Search for the `defaultEsbuildSupported` constant for more information -->
1519

1620
- Chrome >=64
1721
- Firefox >=67

docs/guide/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You can learn more about the rationale behind the project in the [Why Vite](./wh
2222

2323
During development, Vite sets [`esnext` as the transform target](https://esbuild.github.io/api/#target), because we assume a modern browser is used and it supports all of the latest JavaScript and CSS features. This prevents syntax lowering, letting Vite serve modules as close as possible to the original source code.
2424

25-
For the production build, by default Vite targets browsers that support [native ES Modules](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). Legacy browsers can be supported via the official [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy). See the [Building for Production](./build) section for more details.
25+
For the production build, by default Vite targets browsers that support modern JavaScript, such as [native ES Modules](https://caniuse.com/es6-module), [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import), [`import.meta`](https://caniuse.com/mdn-javascript_operators_import_meta), [nullish coalescing](https://caniuse.com/mdn-javascript_operators_nullish_coalescing), and [BigInt](https://caniuse.com/bigint). Legacy browsers can be supported via the official [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy). See the [Building for Production](./build) section for more details.
2626

2727
## Trying Vite Online
2828

packages/vite/src/node/constants.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,20 @@ export const DEFAULT_SERVER_CONDITIONS = Object.freeze(
6464
DEFAULT_CONDITIONS.filter((c) => c !== 'browser'),
6565
)
6666

67-
// Baseline support browserslist
68-
// "defaults and supports es6-module and supports es6-module-dynamic-import"
69-
// Higher browser versions may be needed for extra features.
67+
// Baseline support for:
68+
// - es2020 (covers most of following features)
69+
// - modules via script tag
70+
// - dynamic imports
71+
// - import.meta
72+
// - nullish coalescing (??)
73+
// - bigint
74+
//
75+
// Use this link to check for browser support (excludes es2020):
76+
// https://caniuse.com/es6-module,es6-module-dynamic-import,mdn-javascript_operators_import_meta,mdn-javascript_operators_nullish_coalescing,bigint#:~:text=Feature%20summary
77+
// NOTE: Browser versions may be slightly off as previously the browserslist special `"defaults"` query
78+
// was used around May 2021, which targeted browsers with >0.5% usage at the time.
7079
export const ESBUILD_MODULES_TARGET = [
71-
'es2020', // support import.meta.url
80+
'es2020',
7281
'edge88',
7382
'firefox78',
7483
'chrome87',

packages/vite/src/node/plugins/esbuild.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const jsxExtensionsRE = /\.(?:j|t)sx\b/
3737
// the final build should always support dynamic import and import.meta.
3838
// if they need to be polyfilled, plugin-legacy should be used.
3939
// plugin-legacy detects these two features when checking for modern code.
40+
// Browser support: https://caniuse.com/es6-module-dynamic-import,mdn-javascript_operators_import_meta#:~:text=Feature%20summary
4041
export const defaultEsbuildSupported = {
4142
'dynamic-import': true,
4243
'import-meta': true,

0 commit comments

Comments
 (0)