File tree 2 files changed +11
-5
lines changed
packages/vite/src/node/optimizer
2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -417,11 +417,12 @@ export async function runOptimizeDeps(
417
417
try {
418
418
exportsData = parse ( entryContent ) as ExportsData
419
419
} catch {
420
+ const loader = esbuildOptions . loader ?. [ path . extname ( filePath ) ] || 'jsx'
420
421
debug (
421
- `Unable to parse dependency: ${ id } . Trying again with a JSX transform.`
422
+ `Unable to parse dependency: ${ id } . Trying again with a ${ loader } transform.`
422
423
)
423
424
const transformed = await transformWithEsbuild ( entryContent , filePath , {
424
- loader : 'jsx'
425
+ loader
425
426
} )
426
427
// Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
427
428
// This is useful for packages such as Gatsby.
Original file line number Diff line number Diff line change @@ -463,21 +463,26 @@ function esbuildScanPlugin(
463
463
contents = config . esbuild . jsxInject + `\n` + contents
464
464
}
465
465
466
+ const loader =
467
+ config . optimizeDeps ?. esbuildOptions ?. loader ?. [ `.${ ext } ` ] ||
468
+ ( ext as Loader )
469
+
466
470
if ( contents . includes ( 'import.meta.glob' ) ) {
467
471
return transformGlob (
468
472
contents ,
469
473
id ,
470
474
config . root ,
471
- ext as Loader ,
475
+ loader ,
472
476
resolve ,
473
477
config . logger
474
478
) . then ( ( contents ) => ( {
475
- loader : ext as Loader ,
479
+ loader,
476
480
contents
477
481
} ) )
478
482
}
483
+
479
484
return {
480
- loader : ext as Loader ,
485
+ loader,
481
486
contents
482
487
}
483
488
} )
You can’t perform that action at this time.
0 commit comments