File tree 1 file changed +11
-5
lines changed
packages/plugin-legacy/src
1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,6 @@ import type {
24
24
} from '@babel/core'
25
25
import colors from 'picocolors'
26
26
import browserslist from 'browserslist'
27
- import browserslistToEsbuild from 'browserslist-to-esbuild'
28
27
import type { Options } from './types'
29
28
import {
30
29
detectModernBrowserCode ,
@@ -189,7 +188,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
189
188
const legacyConfigPlugin : Plugin = {
190
189
name : 'vite:legacy-config' ,
191
190
192
- config ( config , env ) {
191
+ async config ( config , env ) {
193
192
if ( env . command === 'build' && ! config . build ?. ssr ) {
194
193
if ( ! config . build ) {
195
194
config . build = { }
@@ -209,9 +208,16 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
209
208
// See https://github.com/vitejs/vite/pull/10052#issuecomment-1242076461
210
209
overriddenBuildTarget = config . build . target !== undefined
211
210
overriddenDefaultModernTargets = options . modernTargets !== undefined
212
- config . build . target = options . modernTargets
213
- ? browserslistToEsbuild ( options . modernTargets )
214
- : modernTargetsEsbuild
211
+
212
+ if ( options . modernTargets ) {
213
+ // Package is ESM only
214
+ const { default : browserslistToEsbuild } = await import (
215
+ 'browserslist-to-esbuild'
216
+ )
217
+ config . build . target = browserslistToEsbuild ( options . modernTargets )
218
+ } else {
219
+ config . build . target = modernTargetsEsbuild
220
+ }
215
221
}
216
222
}
217
223
You can’t perform that action at this time.
0 commit comments