File tree 2 files changed +10
-5
lines changed
packages/vite/src/node/optimizer
2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -304,7 +304,7 @@ const matchesEntireLine = (text: string) => `^${escapeRegex(text)}$`
304
304
// https://github.com/evanw/esbuild/issues/566#issuecomment-735551834
305
305
export function esbuildCjsExternalPlugin (
306
306
externals : string [ ] ,
307
- platform : 'node' | 'browser' ,
307
+ platform : 'node' | 'browser' | 'neutral' ,
308
308
) : Plugin {
309
309
return {
310
310
name : 'cjs-external' ,
Original file line number Diff line number Diff line change @@ -761,7 +761,15 @@ async function prepareEsbuildOptimizerRun(
761
761
) ,
762
762
}
763
763
764
- const platform = environment . config . consumer === 'client' ? 'browser' : 'node'
764
+ const platform =
765
+ optimizeDeps . esbuildOptions ?. platform ??
766
+ // We generally don't want to use platform 'neutral', as esbuild has custom handling
767
+ // when the platform is 'node' or 'browser' that can't be emulated by using mainFields
768
+ // and conditions
769
+ ( environment . config . consumer === 'client' ||
770
+ environment . config . ssr . target === 'webworker'
771
+ ? 'browser'
772
+ : 'node' )
765
773
766
774
const external = [ ...( optimizeDeps ?. exclude ?? [ ] ) ]
767
775
@@ -775,9 +783,6 @@ async function prepareEsbuildOptimizerRun(
775
783
absWorkingDir : process . cwd ( ) ,
776
784
entryPoints : Object . keys ( flatIdDeps ) ,
777
785
bundle : true ,
778
- // We can't use platform 'neutral', as esbuild has custom handling
779
- // when the platform is 'node' or 'browser' that can't be emulated
780
- // by using mainFields and conditions
781
786
platform,
782
787
define,
783
788
format : 'esm' ,
You can’t perform that action at this time.
0 commit comments