feat: resolve conditions for preload

This commit is contained in:
alex8088 2025-01-22 22:24:04 +08:00
parent 4b47ef0bd4
commit 6e8572d9b7

View File

@ -198,6 +198,12 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
const format = pkg.type && pkg.type === 'module' && supportESM() ? 'es' : 'cjs' const format = pkg.type && pkg.type === 'module' && supportESM() ? 'es' : 'cjs'
const defaultConfig = { const defaultConfig = {
ssr: {
resolve: {
conditions: ['module', 'browser', 'development|production'],
mainFields: ['browser', 'module', 'jsnext:main', 'jsnext']
}
},
build: { build: {
outDir: path.resolve(root, 'out', 'preload'), outDir: path.resolve(root, 'out', 'preload'),
target: nodeTarget, target: nodeTarget,
@ -272,7 +278,8 @@ export function electronPreloadVitePlugin(options?: ElectronPluginOptions): Plug
// enable ssr build // enable ssr build
config.build.ssr = true config.build.ssr = true
config.build.ssrEmitAssets = true config.build.ssrEmitAssets = true
config.ssr = { ...config.ssr, ...{ noExternal: true } } config.ssr = mergeConfig(defaultConfig.ssr, config.ssr || {})
config.ssr.noExternal = true
} }
}, },
{ {