Skip to content

Commit 4a8aa82

Browse files
authored
feat!: bump build.target and name it baseline-widely-available (vitejs#20007)
1 parent 999a1ed commit 4a8aa82

File tree

18 files changed

+101
-54
lines changed

18 files changed

+101
-54
lines changed

docs/config/build-options.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Unless noted, the options in this section are only applied to build.
55
## build.target
66

77
- **Type:** `string | string[]`
8-
- **Default:** `'modules'`
8+
- **Default:** `'baseline-widely-available'`
99
- **Related:** [Browser Compatibility](/guide/build#browser-compatibility)
1010

11-
Browser compatibility target for the final bundle. The default value is a Vite special value, `'modules'`, which targets browsers with [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) support. Vite will replace `'modules'` to `['es2020', 'edge88', 'firefox78', 'chrome87', 'safari14']`
11+
Browser compatibility target for the final bundle. The default value is a Vite special value, `'baseline-widely-available'`, which targets browsers that are included in the [Baseline](https://web-platform-dx.github.io/web-features/) Widely Available on 2025-05-01. Specifically, it is `['chrome107', 'edge107', 'firefox104', 'safari16']`.
1212

1313
Another special value is `'esnext'` - which assumes native dynamic imports support and will only perform minimal transpiling.
1414

docs/guide/build.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ 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, 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:
7+
By default, the production bundle assumes a modern browser that is included in the [Baseline](https://web-platform-dx.github.io/web-features/) Widely Available targets. The default browser support range is:
88

9-
<!-- Search for the `ESBUILD_MODULES_TARGET` constant for more information -->
9+
<!-- Search for the `ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET` constant for more information -->
1010

11-
- Chrome >=87
12-
- Firefox >=78
13-
- Safari >=14
14-
- Edge >=88
11+
- Chrome >=107
12+
- Edge >=107
13+
- Firefox >=104
14+
- Safari >=16
1515

1616
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):
1717

docs/guide/index.md

Lines changed: 1 addition & 1 deletion
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 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.
25+
For production builds, Vite by default targets [Baseline](https://web-platform-dx.github.io/web-features/) Widely Available browsers. These are browsers that were released at least 2.5 years ago. The target can be lowered via configuration. Additionally, 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/create-vite/template-lit-ts/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2020",
3+
"target": "ES2022",
44
"experimentalDecorators": true,
55
"useDefineForClassFields": false,
66
"module": "ESNext",
7-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
7+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
88
"skipLibCheck": true,
99

1010
/* Bundler mode */

packages/create-vite/template-preact-ts/tsconfig.app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"compilerOptions": {
33
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4-
"target": "ES2020",
4+
"target": "ES2022",
55
"useDefineForClassFields": true,
66
"module": "ESNext",
7-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
7+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
88
"skipLibCheck": true,
99
"paths": {
1010
"react": ["./node_modules/preact/compat/"],

packages/create-vite/template-qwik-ts/tsconfig.app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"compilerOptions": {
33
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4-
"target": "ES2020",
4+
"target": "ES2022",
55
"useDefineForClassFields": true,
66
"module": "ESNext",
7-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
7+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
88
"skipLibCheck": true,
99

1010
/* Bundler mode */

packages/create-vite/template-react-ts/tsconfig.app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
33
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4-
"target": "ES2020",
4+
"target": "ES2022",
55
"useDefineForClassFields": true,
6-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
6+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
77
"module": "ESNext",
88
"skipLibCheck": true,
99

packages/create-vite/template-solid-ts/tsconfig.app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"compilerOptions": {
33
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4-
"target": "ES2020",
4+
"target": "ES2022",
55
"useDefineForClassFields": true,
66
"module": "ESNext",
7-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
7+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
88
"skipLibCheck": true,
99

1010
/* Bundler mode */

packages/create-vite/template-svelte-ts/tsconfig.app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "@tsconfig/svelte/tsconfig.json",
33
"compilerOptions": {
4-
"target": "ESNext",
4+
"target": "ES2022",
55
"useDefineForClassFields": true,
66
"module": "ESNext",
77
"resolveJsonModule": true,

packages/create-vite/template-vanilla-ts/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2020",
3+
"target": "ES2022",
44
"useDefineForClassFields": true,
55
"module": "ESNext",
6-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
6+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
77
"skipLibCheck": true,
88

99
/* Bundler mode */

packages/vite/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"typecheck": "tsc --noEmit && tsc --noEmit -p src/node",
7878
"lint": "eslint --cache --ext .ts src/**",
7979
"format": "prettier --write --cache --parser typescript \"src/**/*.ts\"",
80+
"generate-target": "tsx scripts/generateTarget.ts",
8081
"prepublishOnly": "npm run build"
8182
},
8283
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
@@ -106,6 +107,7 @@
106107
"@types/escape-html": "^1.0.4",
107108
"@types/pnpapi": "^0.0.5",
108109
"artichokie": "^0.3.1",
110+
"baseline-browser-mapping": "^2.3.0",
109111
"cac": "^6.7.14",
110112
"chokidar": "^3.6.0",
111113
"connect": "^3.7.0",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { getCompatibleVersions } from 'baseline-browser-mapping'
2+
3+
// Update on each major release
4+
const targetDate = '2025-05-01'
5+
6+
// https://esbuild.github.io/api/#target
7+
const esbuildSupportedBrowsers = new Set([
8+
'chrome',
9+
'edge',
10+
'firefox',
11+
'safari',
12+
])
13+
14+
const results = getCompatibleVersions({
15+
widelyAvailableOnDate: targetDate,
16+
})
17+
18+
const esbuildTargets = results
19+
.filter((target) => esbuildSupportedBrowsers.has(target.browser))
20+
.map((target) => `${target.browser}${target.version}`)
21+
22+
console.log('ESBuild Targets:', esbuildTargets)

packages/vite/src/node/build.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type { TransformOptions } from 'esbuild'
2727
import { withTrailingSlash } from '../shared/utils'
2828
import {
2929
DEFAULT_ASSETS_INLINE_LIMIT,
30-
ESBUILD_MODULES_TARGET,
30+
ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
3131
ROLLUP_HOOKS,
3232
VERSION,
3333
} from './constants'
@@ -86,18 +86,18 @@ export interface BuildEnvironmentOptions {
8686
* and the lowest supported target is es2015. Note this only handles
8787
* syntax transformation and does not cover polyfills
8888
*
89-
* Default: 'modules' - transpile targeting browsers that natively support
90-
* dynamic es module imports and `import.meta`
91-
* (Chrome 87+, Firefox 78+, Safari 14+, Edge 88+).
89+
* Default: 'baseline-widely-available' - transpile targeting browsers that
90+
* are included in the Baseline Widely Available on 2025-05-01.
91+
* (Chrome 107+, Edge 107+, Firefox 104+, Safari 16+).
9292
*
9393
* Another special value is 'esnext' - which only performs minimal transpiling
9494
* (for minification compat).
9595
*
9696
* For custom targets, see https://esbuild.github.io/api/#target and
9797
* https://esbuild.github.io/content-types/#javascript for more details.
98-
* @default 'modules'
98+
* @default 'baseline-widely-available'
9999
*/
100-
target?: 'modules' | TransformOptions['target'] | false
100+
target?: 'baseline-widely-available' | TransformOptions['target'] | false
101101
/**
102102
* whether to inject module preload polyfill.
103103
* Note: does not apply to library mode.
@@ -353,7 +353,7 @@ export interface ResolvedBuildOptions
353353
}
354354

355355
export const buildEnvironmentOptionsDefaults = Object.freeze({
356-
target: 'modules',
356+
target: 'baseline-widely-available',
357357
/** @deprecated */
358358
polyfillModulePreload: true,
359359
modulePreload: true,
@@ -423,8 +423,8 @@ export function resolveBuildEnvironmentOptions(
423423
)
424424

425425
// handle special build targets
426-
if (merged.target === 'modules') {
427-
merged.target = ESBUILD_MODULES_TARGET
426+
if (merged.target === 'baseline-widely-available') {
427+
merged.target = ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET
428428
}
429429

430430
// normalize false string into actual false

packages/vite/src/node/cli.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ cli
267267
// build
268268
cli
269269
.command('build [root]', 'build for production')
270-
.option('--target <target>', `[string] transpile target (default: 'modules')`)
270+
.option(
271+
'--target <target>',
272+
`[string] transpile target (default: 'baseline-widely-available')`,
273+
)
271274
.option('--outDir <dir>', `[string] output directory (default: dist)`)
272275
.option(
273276
'--assetsDir <dir>',

packages/vite/src/node/constants.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,18 @@ export const DEFAULT_SERVER_CONDITIONS = Object.freeze(
6464
DEFAULT_CONDITIONS.filter((c) => c !== 'browser'),
6565
)
6666

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.
79-
export const ESBUILD_MODULES_TARGET = [
80-
'es2020',
81-
'edge88',
82-
'firefox78',
83-
'chrome87',
84-
'safari14',
67+
/**
68+
* The browser versions that are included in the Baseline Widely Available on 2025-05-01.
69+
*
70+
* This value would be bumped on each major release of Vite.
71+
*
72+
* The value is generated by `pnpm generate-target` script.
73+
*/
74+
export const ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET = [
75+
'chrome107',
76+
'edge107',
77+
'firefox104',
78+
'safari16',
8579
]
8680

8781
export const DEFAULT_CONFIG_FILES = [

packages/vite/src/node/optimizer/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import {
2525
defaultEsbuildSupported,
2626
transformWithEsbuild,
2727
} from '../plugins/esbuild'
28-
import { ESBUILD_MODULES_TARGET, METADATA_FILENAME } from '../constants'
28+
import {
29+
ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
30+
METADATA_FILENAME,
31+
} from '../constants'
2932
import { isWindows } from '../../shared/utils'
3033
import type { Environment } from '../environment'
3134
import { esbuildCjsExternalPlugin, esbuildDepPlugin } from './esbuildDepPlugin'
@@ -834,7 +837,7 @@ async function prepareEsbuildOptimizerRun(
834837
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`,
835838
}
836839
: undefined,
837-
target: ESBUILD_MODULES_TARGET,
840+
target: ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
838841
external,
839842
logLevel: 'error',
840843
splitting: true,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
CLIENT_PUBLIC_PATH,
5252
CSS_LANGS_RE,
5353
DEV_PROD_CONDITION,
54-
ESBUILD_MODULES_TARGET,
54+
ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
5555
SPECIAL_QUERY_RE,
5656
} from '../constants'
5757
import type { ResolvedConfig } from '../config'
@@ -218,7 +218,9 @@ export function resolveCSSOptions(
218218
const resolved = mergeWithDefaults(cssConfigDefaults, options ?? {})
219219
if (resolved.transformer === 'lightningcss') {
220220
resolved.lightningcss ??= {}
221-
resolved.lightningcss.targets ??= convertTargets(ESBUILD_MODULES_TARGET)
221+
resolved.lightningcss.targets ??= convertTargets(
222+
ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
223+
)
222224
}
223225
return resolved
224226
}

pnpm-lock.yaml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)