Skip to content

Commit 0924879

Browse files
dario-piotrowiczsapphi-red
andauthoredNov 8, 2024··
feat(optimizer): allow users to specify their esbuild platform option (#18611)
Co-authored-by: 翠 / green <green@sapphi.red>
1 parent 2c6d3db commit 0924879

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed
 

‎packages/vite/src/node/optimizer/esbuildDepPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ const matchesEntireLine = (text: string) => `^${escapeRegex(text)}$`
304304
// https://github.com/evanw/esbuild/issues/566#issuecomment-735551834
305305
export function esbuildCjsExternalPlugin(
306306
externals: string[],
307-
platform: 'node' | 'browser',
307+
platform: 'node' | 'browser' | 'neutral',
308308
): Plugin {
309309
return {
310310
name: 'cjs-external',

‎packages/vite/src/node/optimizer/index.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,15 @@ async function prepareEsbuildOptimizerRun(
761761
),
762762
}
763763

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')
765773

766774
const external = [...(optimizeDeps?.exclude ?? [])]
767775

@@ -775,9 +783,6 @@ async function prepareEsbuildOptimizerRun(
775783
absWorkingDir: process.cwd(),
776784
entryPoints: Object.keys(flatIdDeps),
777785
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
781786
platform,
782787
define,
783788
format: 'esm',

0 commit comments

Comments
 (0)
Please sign in to comment.