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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions docs/config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

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 @@ -338,7 +337,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 @@ -419,21 +417,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 @@ -625,7 +625,6 @@ export function resolveDevEnvironmentOptions(

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

Expand Down