Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: bump minimal terser version to 5.16.0 #18209

Merged
merged 2 commits into from
Oct 23, 2024
Merged
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
5 changes: 1 addition & 4 deletions docs/config/build-options.md
Original file line number Diff line number Diff line change
@@ -10,10 +10,7 @@ Unless noted, the options in this section are only applied to build.

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

Another special value is `'esnext'` - which assumes native dynamic imports support and will transpile as little as possible:

- If the [`build.minify`](#build-minify) option is `'terser'` and the installed Terser version is below 5.16.0, `'esnext'` will be forced down to `'es2021'`.
- In other cases, it will perform no transpilation at all.
Another special value is `'esnext'` - which assumes native dynamic imports support and will only perform minimal transpiling.

The transform is performed with esbuild and the value should be a valid [esbuild target option](https://esbuild.github.io/api/#target). Custom targets can either be an ES version (e.g. `es2015`), a browser with version (e.g. `chrome58`), or an array of multiple target strings.

2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@
"sass-embedded": "*",
"stylus": "*",
"sugarss": "*",
"terser": "^5.4.0"
"terser": "^5.16.0"
},
"peerDependenciesMeta": {
"@types/node": {
17 changes: 0 additions & 17 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
@@ -47,7 +47,6 @@ import {
joinUrlSegments,
normalizePath,
partialEncodeURIPath,
requireResolveFromRootWithFallback,
} from './utils'
import { resolveEnvironmentPlugins } from './plugin'
import { manifestPlugin } from './plugins/manifest'
@@ -341,7 +340,6 @@ export interface ResolvedBuildOptions
export function resolveBuildEnvironmentOptions(
raw: BuildEnvironmentOptions,
logger: Logger,
root: string,
consumer: 'client' | 'server' | undefined,
): ResolvedBuildEnvironmentOptions {
const deprecatedPolyfillModulePreload = raw?.polyfillModulePreload
@@ -422,21 +420,6 @@ export function resolveBuildEnvironmentOptions(
// handle special build targets
if (resolved.target === 'modules') {
resolved.target = ESBUILD_MODULES_TARGET
} else if (resolved.target === 'esnext' && resolved.minify === 'terser') {
try {
const terserPackageJsonPath = requireResolveFromRootWithFallback(
root,
'terser/package.json',
)
const terserPackageJson = JSON.parse(
fs.readFileSync(terserPackageJsonPath, 'utf-8'),
)
const v = terserPackageJson.version.split('.')
if (v[0] === '5' && v[1] < 16) {
// esnext + terser 5.16<: limit to es2021 so it can be minified by terser
resolved.target = 'es2021'
}
} catch {}
}

if (!resolved.cssTarget) {
4 changes: 0 additions & 4 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
@@ -626,7 +626,6 @@ export function resolveDevEnvironmentOptions(

function resolveEnvironmentOptions(
options: EnvironmentOptions,
resolvedRoot: string,
alias: Alias[],
preserveSymlinks: boolean,
logger: Logger,
@@ -657,7 +656,6 @@ function resolveEnvironmentOptions(
build: resolveBuildEnvironmentOptions(
options.build ?? {},
logger,
resolvedRoot,
consumer,
),
}
@@ -989,7 +987,6 @@ export async function resolveConfig(
for (const environmentName of Object.keys(config.environments)) {
resolvedEnvironments[environmentName] = resolveEnvironmentOptions(
config.environments[environmentName],
resolvedRoot,
resolvedDefaultResolve.alias,
resolvedDefaultResolve.preserveSymlinks,
logger,
@@ -1016,7 +1013,6 @@ export async function resolveConfig(
const resolvedBuildOptions = resolveBuildEnvironmentOptions(
config.build ?? {},
logger,
resolvedRoot,
undefined,
)