From 19ce525b974328e4668ad8c6540c2a5ea652795b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 23 Oct 2024 19:33:31 +0900 Subject: [PATCH] refactor!: bump minimal terser version to 5.16.0 (#18209) --- docs/config/build-options.md | 5 +---- packages/vite/package.json | 2 +- packages/vite/src/node/build.ts | 17 ----------------- packages/vite/src/node/config.ts | 4 ---- 4 files changed, 2 insertions(+), 26 deletions(-) diff --git a/docs/config/build-options.md b/docs/config/build-options.md index 2b82413fc0e026..9bff0380a6a02c 100644 --- a/docs/config/build-options.md +++ b/docs/config/build-options.md @@ -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. diff --git a/packages/vite/package.json b/packages/vite/package.json index ffd0c9777ceb39..398fa6a153ab04 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -162,7 +162,7 @@ "sass-embedded": "*", "stylus": "*", "sugarss": "*", - "terser": "^5.4.0" + "terser": "^5.16.0" }, "peerDependenciesMeta": { "@types/node": { diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 339161192c391e..8f27e66022a3e8 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -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) { diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index c3ba03076c6c49..51586ade5dff54 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -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, )