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

fix(plugin-legacy): dynamic import browserslist-to-esbuild #16011

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import type {
} from '@babel/core'
import colors from 'picocolors'
import browserslist from 'browserslist'
import browserslistToEsbuild from 'browserslist-to-esbuild'
import type { Options } from './types'
import {
detectModernBrowserCode,
Expand Down Expand Up @@ -189,7 +188,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
const legacyConfigPlugin: Plugin = {
name: 'vite:legacy-config',

config(config, env) {
async config(config, env) {
if (env.command === 'build' && !config.build?.ssr) {
if (!config.build) {
config.build = {}
Expand All @@ -209,6 +208,11 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
// See https://github.com/vitejs/vite/pull/10052#issuecomment-1242076461
overriddenBuildTarget = config.build.target !== undefined
overriddenDefaultModernTargets = options.modernTargets !== undefined

// Package is ESM only
const { default: browserslistToEsbuild } = await import(
'browserslist-to-esbuild'
)
bluwy marked this conversation as resolved.
Show resolved Hide resolved
config.build.target = options.modernTargets
? browserslistToEsbuild(options.modernTargets)
: modernTargetsEsbuild
Expand Down