Refactor static build config merge (#4344)
This commit is contained in:
parent
675b6d47f4
commit
500332a426
2 changed files with 9 additions and 22 deletions
5
.changeset/giant-ants-smoke.md
Normal file
5
.changeset/giant-ants-smoke.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Refactor static build config merge
|
|
@ -116,19 +116,16 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
|
||||||
const out = ssr ? opts.buildConfig.server : astroConfig.outDir;
|
const out = ssr ? opts.buildConfig.server : astroConfig.outDir;
|
||||||
|
|
||||||
const viteBuildConfig: ViteConfigWithSSR = {
|
const viteBuildConfig: ViteConfigWithSSR = {
|
||||||
|
...viteConfig,
|
||||||
logLevel: opts.viteConfig.logLevel ?? 'error',
|
logLevel: opts.viteConfig.logLevel ?? 'error',
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
css: viteConfig.css,
|
|
||||||
optimizeDeps: {
|
|
||||||
include: [...(viteConfig.optimizeDeps?.include ?? [])],
|
|
||||||
exclude: [...(viteConfig.optimizeDeps?.exclude ?? [])],
|
|
||||||
},
|
|
||||||
build: {
|
build: {
|
||||||
...viteConfig.build,
|
...viteConfig.build,
|
||||||
emptyOutDir: false,
|
emptyOutDir: false,
|
||||||
manifest: false,
|
manifest: false,
|
||||||
outDir: fileURLToPath(out),
|
outDir: fileURLToPath(out),
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
|
...viteConfig.build?.rollupOptions,
|
||||||
input: [],
|
input: [],
|
||||||
output: {
|
output: {
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
|
@ -138,7 +135,6 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
|
||||||
entryFileNames: opts.buildConfig.serverEntry,
|
entryFileNames: opts.buildConfig.serverEntry,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
ssr: true,
|
ssr: true,
|
||||||
// must match an esbuild target
|
// must match an esbuild target
|
||||||
target: 'esnext',
|
target: 'esnext',
|
||||||
|
@ -163,12 +159,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
|
||||||
vitePluginAnalyzer(internals),
|
vitePluginAnalyzer(internals),
|
||||||
],
|
],
|
||||||
publicDir: ssr ? false : viteConfig.publicDir,
|
publicDir: ssr ? false : viteConfig.publicDir,
|
||||||
root: viteConfig.root,
|
|
||||||
envPrefix: 'PUBLIC_',
|
envPrefix: 'PUBLIC_',
|
||||||
server: viteConfig.server,
|
|
||||||
base: astroConfig.base,
|
|
||||||
ssr: viteConfig.ssr,
|
|
||||||
resolve: viteConfig.resolve,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
await runHookBuildSetup({
|
await runHookBuildSetup({
|
||||||
|
@ -178,7 +169,6 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
|
||||||
target: 'server',
|
target: 'server',
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: use vite.mergeConfig() here?
|
|
||||||
return await vite.build(viteBuildConfig);
|
return await vite.build(viteBuildConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,23 +192,19 @@ async function clientBuild(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use vite.mergeConfig() here?
|
|
||||||
info(opts.logging, null, `\n${bgGreen(black(' building client '))}`);
|
info(opts.logging, null, `\n${bgGreen(black(' building client '))}`);
|
||||||
|
|
||||||
const viteBuildConfig = {
|
const viteBuildConfig = {
|
||||||
|
...viteConfig,
|
||||||
logLevel: 'info',
|
logLevel: 'info',
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
css: viteConfig.css,
|
|
||||||
optimizeDeps: {
|
|
||||||
include: [...(viteConfig.optimizeDeps?.include ?? [])],
|
|
||||||
exclude: [...(viteConfig.optimizeDeps?.exclude ?? [])],
|
|
||||||
},
|
|
||||||
build: {
|
build: {
|
||||||
...viteConfig.build,
|
...viteConfig.build,
|
||||||
emptyOutDir: false,
|
emptyOutDir: false,
|
||||||
minify: 'esbuild',
|
minify: 'esbuild',
|
||||||
outDir: fileURLToPath(out),
|
outDir: fileURLToPath(out),
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
|
...viteConfig.build?.rollupOptions,
|
||||||
input: Array.from(input),
|
input: Array.from(input),
|
||||||
output: {
|
output: {
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
|
@ -242,11 +228,7 @@ async function clientBuild(
|
||||||
}),
|
}),
|
||||||
...(viteConfig.plugins || []),
|
...(viteConfig.plugins || []),
|
||||||
],
|
],
|
||||||
publicDir: viteConfig.publicDir,
|
|
||||||
root: viteConfig.root,
|
|
||||||
envPrefix: 'PUBLIC_',
|
envPrefix: 'PUBLIC_',
|
||||||
server: viteConfig.server,
|
|
||||||
base: astroConfig.base,
|
|
||||||
} as ViteConfigWithSSR;
|
} as ViteConfigWithSSR;
|
||||||
|
|
||||||
await runHookBuildSetup({
|
await runHookBuildSetup({
|
||||||
|
|
Loading…
Reference in a new issue