Skip to content

Commit

Permalink
refactor!: bump minimal terser version to 5.16.0 (#18209)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Oct 23, 2024
1 parent b57321c commit 19ce525
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 26 deletions.
5 changes: 1 addition & 4 deletions docs/config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"sass-embedded": "*",
"stylus": "*",
"sugarss": "*",
"terser": "^5.4.0"
"terser": "^5.16.0"
},
"peerDependenciesMeta": {
"@types/node": {
Expand Down
17 changes: 0 additions & 17 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import {
joinUrlSegments,
normalizePath,
partialEncodeURIPath,
requireResolveFromRootWithFallback,
} from './utils'
import { resolveEnvironmentPlugins } from './plugin'
import { manifestPlugin } from './plugins/manifest'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,6 @@ export function resolveDevEnvironmentOptions(

function resolveEnvironmentOptions(
options: EnvironmentOptions,
resolvedRoot: string,
alias: Alias[],
preserveSymlinks: boolean,
logger: Logger,
Expand Down Expand Up @@ -657,7 +656,6 @@ function resolveEnvironmentOptions(
build: resolveBuildEnvironmentOptions(
options.build ?? {},
logger,
resolvedRoot,
consumer,
),
}
Expand Down Expand Up @@ -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,
Expand All @@ -1016,7 +1013,6 @@ export async function resolveConfig(
const resolvedBuildOptions = resolveBuildEnvironmentOptions(
config.build ?? {},
logger,
resolvedRoot,
undefined,
)

Expand Down

0 comments on commit 19ce525

Please sign in to comment.