mirror of
https://github.com/alex8088/electron-vite.git
synced 2026-04-29 17:28:15 +08:00
perf: setup rollupOption compatibility via config factory
This commit is contained in:
parent
4bede21c81
commit
31965d2972
@ -195,20 +195,14 @@ export async function resolveConfig(
|
||||
const { main, preload, renderer } = loadResult.config
|
||||
|
||||
if (main) {
|
||||
main.build ??= {}
|
||||
setupRollupOptionCompat(main.build)
|
||||
userConfig.main = await new MainConfigFactory(main, config, { outDir, root }).build()
|
||||
}
|
||||
|
||||
if (preload) {
|
||||
preload.build ??= {}
|
||||
setupRollupOptionCompat(preload.build)
|
||||
userConfig.preload = await new PreloadConfigFactory(preload, config, { outDir, root }).build()
|
||||
}
|
||||
|
||||
if (renderer) {
|
||||
renderer.build ??= {}
|
||||
setupRollupOptionCompat(renderer.build)
|
||||
userConfig.renderer = await new RendererConfigFactory(renderer, config, { outDir, root }).build()
|
||||
}
|
||||
|
||||
@ -226,20 +220,15 @@ export async function resolveConfig(
|
||||
return resolved
|
||||
}
|
||||
|
||||
function setupRollupOptionCompat<T extends Pick<ViteBuildOptions, 'rollupOptions' | 'rolldownOptions'>>(
|
||||
buildConfig: T
|
||||
): asserts buildConfig is T & {
|
||||
rolldownOptions: Exclude<T['rolldownOptions'], undefined>
|
||||
} {
|
||||
buildConfig.rolldownOptions ??= buildConfig.rollupOptions
|
||||
}
|
||||
|
||||
export abstract class ConfigFactory<T extends MainViteConfig | PreloadViteConfig | RendererViteConfig> {
|
||||
constructor(
|
||||
protected readonly baseConfig: T,
|
||||
protected readonly inlineConfig: InlineConfig,
|
||||
protected readonly options: { outDir?: string; root?: string }
|
||||
) {}
|
||||
) {
|
||||
baseConfig.build ??= {}
|
||||
baseConfig.build.rolldownOptions ??= baseConfig.build.rollupOptions
|
||||
}
|
||||
|
||||
async build(cleanMode?: boolean): Promise<T> {
|
||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user