Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Unless noted, the options in this section are only applied to build.
## build.target

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

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']`
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']`.

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

Expand Down
12 changes: 6 additions & 6 deletions docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ When it is time to deploy your app for production, simply run the `vite build` c

## Browser Compatibility

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:
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:

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

- Chrome >=87
- Firefox >=78
- Safari >=14
- Edge >=88
- Chrome >=107
- Edge >=107
- Firefox >=104
- Safari >=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):

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ You can learn more about the rationale behind the project in the [Why Vite](./wh

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.

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.
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.

## Trying Vite Online

Expand Down
4 changes: 2 additions & 2 deletions packages/create-vite/template-lit-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"experimentalDecorators": true,
"useDefineForClassFields": false,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions packages/create-vite/template-preact-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"paths": {
"react": ["./node_modules/preact/compat/"],
Expand Down
4 changes: 2 additions & 2 deletions packages/create-vite/template-qwik-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions packages/create-vite/template-react-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

Expand Down
4 changes: 2 additions & 2 deletions packages/create-vite/template-solid-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-svelte-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"resolveJsonModule": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/create-vite/template-vanilla-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
2 changes: 2 additions & 0 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"typecheck": "tsc --noEmit && tsc --noEmit -p src/node",
"lint": "eslint --cache --ext .ts src/**",
"format": "prettier --write --cache --parser typescript \"src/**/*.ts\"",
"generate-target": "tsx scripts/generateTarget.ts",
"prepublishOnly": "npm run build"
},
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
Expand Down Expand Up @@ -109,6 +110,7 @@
"@types/escape-html": "^1.0.4",
"@types/pnpapi": "^0.0.5",
"artichokie": "^0.3.1",
"baseline-browser-mapping": "^2.3.0",
"cac": "^6.7.14",
"chokidar": "^3.6.0",
"connect": "^3.7.0",
Expand Down
22 changes: 22 additions & 0 deletions packages/vite/scripts/generateTarget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { getCompatibleVersions } from 'baseline-browser-mapping'

// Update on each major release
const targetDate = '2025-05-01'

// https://esbuild.github.io/api/#target
const esbuildSupportedBrowsers = new Set([
'chrome',
'edge',
'firefox',
'safari',
])

const results = getCompatibleVersions({
widelyAvailableOnDate: targetDate,
})

const esbuildTargets = results
.filter((target) => esbuildSupportedBrowsers.has(target.browser))
.map((target) => `${target.browser}${target.version}`)

console.log('ESBuild Targets:', esbuildTargets)
18 changes: 9 additions & 9 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type { TransformOptions } from 'esbuild'
import { withTrailingSlash } from '../shared/utils'
import {
DEFAULT_ASSETS_INLINE_LIMIT,
ESBUILD_MODULES_TARGET,
ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
ROLLUP_HOOKS,
VERSION,
} from './constants'
Expand Down Expand Up @@ -86,18 +86,18 @@ export interface BuildEnvironmentOptions {
* and the lowest supported target is es2015. Note this only handles
* syntax transformation and does not cover polyfills
*
* Default: 'modules' - transpile targeting browsers that natively support
* dynamic es module imports and `import.meta`
* (Chrome 87+, Firefox 78+, Safari 14+, Edge 88+).
* Default: 'baseline-widely-available' - transpile targeting browsers that
* are included in the Baseline Widely Available on 2025-05-01.
* (Chrome 107+, Edge 107+, Firefox 104+, Safari 16+).
*
* Another special value is 'esnext' - which only performs minimal transpiling
* (for minification compat).
*
* For custom targets, see https://esbuild.github.io/api/#target and
* https://esbuild.github.io/content-types/#javascript for more details.
* @default 'modules'
* @default 'baseline-widely-available'
*/
target?: 'modules' | TransformOptions['target'] | false
target?: 'baseline-widely-available' | TransformOptions['target'] | false
/**
* whether to inject module preload polyfill.
* Note: does not apply to library mode.
Expand Down Expand Up @@ -353,7 +353,7 @@ export interface ResolvedBuildOptions
}

export const buildEnvironmentOptionsDefaults = Object.freeze({
target: 'modules',
target: 'baseline-widely-available',
/** @deprecated */
polyfillModulePreload: true,
modulePreload: true,
Expand Down Expand Up @@ -423,8 +423,8 @@ export function resolveBuildEnvironmentOptions(
)

// handle special build targets
if (merged.target === 'modules') {
merged.target = ESBUILD_MODULES_TARGET
if (merged.target === 'baseline-widely-available') {
merged.target = ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET
}

// normalize false string into actual false
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ cli
// build
cli
.command('build [root]', 'build for production')
.option('--target <target>', `[string] transpile target (default: 'modules')`)
.option(
'--target <target>',
`[string] transpile target (default: 'baseline-widely-available')`,
)
.option('--outDir <dir>', `[string] output directory (default: dist)`)
.option(
'--assetsDir <dir>',
Expand Down
30 changes: 12 additions & 18 deletions packages/vite/src/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,18 @@ export const DEFAULT_SERVER_CONDITIONS = Object.freeze(
DEFAULT_CONDITIONS.filter((c) => c !== 'browser'),
)

// Baseline support for:
// - es2020 (covers most of following features)
// - modules via script tag
// - dynamic imports
// - import.meta
// - nullish coalescing (??)
// - bigint
//
// Use this link to check for browser support (excludes es2020):
// https://caniuse.com/es6-module,es6-module-dynamic-import,mdn-javascript_operators_import_meta,mdn-javascript_operators_nullish_coalescing,bigint#:~:text=Feature%20summary
// NOTE: Browser versions may be slightly off as previously the browserslist special `"defaults"` query
// was used around May 2021, which targeted browsers with >0.5% usage at the time.
export const ESBUILD_MODULES_TARGET = [
'es2020',
'edge88',
'firefox78',
'chrome87',
'safari14',
/**
* The browser versions that are included in the Baseline Widely Available on 2025-05-01.
*
* This value would be bumped on each major release of Vite.
*
* The value is generated by `pnpm generate-target` script.
*/
export const ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET = [
'chrome107',
'edge107',
'firefox104',
'safari16',
]

export const DEFAULT_CONFIG_FILES = [
Expand Down
7 changes: 5 additions & 2 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import {
defaultEsbuildSupported,
transformWithEsbuild,
} from '../plugins/esbuild'
import { ESBUILD_MODULES_TARGET, METADATA_FILENAME } from '../constants'
import {
ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
METADATA_FILENAME,
} from '../constants'
import { isWindows } from '../../shared/utils'
import type { Environment } from '../environment'
import { esbuildCjsExternalPlugin, esbuildDepPlugin } from './esbuildDepPlugin'
Expand Down Expand Up @@ -834,7 +837,7 @@ async function prepareEsbuildOptimizerRun(
js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`,
}
: undefined,
target: ESBUILD_MODULES_TARGET,
target: ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
external,
logLevel: 'error',
splitting: true,
Expand Down
6 changes: 4 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
CLIENT_PUBLIC_PATH,
CSS_LANGS_RE,
DEV_PROD_CONDITION,
ESBUILD_MODULES_TARGET,
ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
SPECIAL_QUERY_RE,
} from '../constants'
import type { ResolvedConfig } from '../config'
Expand Down Expand Up @@ -218,7 +218,9 @@ export function resolveCSSOptions(
const resolved = mergeWithDefaults(cssConfigDefaults, options ?? {})
if (resolved.transformer === 'lightningcss') {
resolved.lightningcss ??= {}
resolved.lightningcss.targets ??= convertTargets(ESBUILD_MODULES_TARGET)
resolved.lightningcss.targets ??= convertTargets(
ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
)
}
return resolved
}
Expand Down
21 changes: 21 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.