Skip to content

Commit 19ce525

Browse files
authoredOct 23, 2024··
refactor!: bump minimal terser version to 5.16.0 (#18209)
1 parent b57321c commit 19ce525

File tree

4 files changed

+2
-26
lines changed

4 files changed

+2
-26
lines changed
 

‎docs/config/build-options.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ Unless noted, the options in this section are only applied to build.
1010

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

13-
Another special value is `'esnext'` - which assumes native dynamic imports support and will transpile as little as possible:
14-
15-
- 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'`.
16-
- In other cases, it will perform no transpilation at all.
13+
Another special value is `'esnext'` - which assumes native dynamic imports support and will only perform minimal transpiling.
1714

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

‎packages/vite/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
"sass-embedded": "*",
163163
"stylus": "*",
164164
"sugarss": "*",
165-
"terser": "^5.4.0"
165+
"terser": "^5.16.0"
166166
},
167167
"peerDependenciesMeta": {
168168
"@types/node": {

‎packages/vite/src/node/build.ts

-17
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import {
4747
joinUrlSegments,
4848
normalizePath,
4949
partialEncodeURIPath,
50-
requireResolveFromRootWithFallback,
5150
} from './utils'
5251
import { resolveEnvironmentPlugins } from './plugin'
5352
import { manifestPlugin } from './plugins/manifest'
@@ -341,7 +340,6 @@ export interface ResolvedBuildOptions
341340
export function resolveBuildEnvironmentOptions(
342341
raw: BuildEnvironmentOptions,
343342
logger: Logger,
344-
root: string,
345343
consumer: 'client' | 'server' | undefined,
346344
): ResolvedBuildEnvironmentOptions {
347345
const deprecatedPolyfillModulePreload = raw?.polyfillModulePreload
@@ -422,21 +420,6 @@ export function resolveBuildEnvironmentOptions(
422420
// handle special build targets
423421
if (resolved.target === 'modules') {
424422
resolved.target = ESBUILD_MODULES_TARGET
425-
} else if (resolved.target === 'esnext' && resolved.minify === 'terser') {
426-
try {
427-
const terserPackageJsonPath = requireResolveFromRootWithFallback(
428-
root,
429-
'terser/package.json',
430-
)
431-
const terserPackageJson = JSON.parse(
432-
fs.readFileSync(terserPackageJsonPath, 'utf-8'),
433-
)
434-
const v = terserPackageJson.version.split('.')
435-
if (v[0] === '5' && v[1] < 16) {
436-
// esnext + terser 5.16<: limit to es2021 so it can be minified by terser
437-
resolved.target = 'es2021'
438-
}
439-
} catch {}
440423
}
441424

442425
if (!resolved.cssTarget) {

‎packages/vite/src/node/config.ts

-4
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,6 @@ export function resolveDevEnvironmentOptions(
626626

627627
function resolveEnvironmentOptions(
628628
options: EnvironmentOptions,
629-
resolvedRoot: string,
630629
alias: Alias[],
631630
preserveSymlinks: boolean,
632631
logger: Logger,
@@ -657,7 +656,6 @@ function resolveEnvironmentOptions(
657656
build: resolveBuildEnvironmentOptions(
658657
options.build ?? {},
659658
logger,
660-
resolvedRoot,
661659
consumer,
662660
),
663661
}
@@ -989,7 +987,6 @@ export async function resolveConfig(
989987
for (const environmentName of Object.keys(config.environments)) {
990988
resolvedEnvironments[environmentName] = resolveEnvironmentOptions(
991989
config.environments[environmentName],
992-
resolvedRoot,
993990
resolvedDefaultResolve.alias,
994991
resolvedDefaultResolve.preserveSymlinks,
995992
logger,
@@ -1016,7 +1013,6 @@ export async function resolveConfig(
10161013
const resolvedBuildOptions = resolveBuildEnvironmentOptions(
10171014
config.build ?? {},
10181015
logger,
1019-
resolvedRoot,
10201016
undefined,
10211017
)
10221018

0 commit comments

Comments
 (0)
Please sign in to comment.