Skip to content

Commit

Permalink
Refactor static build config merge (#4344)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Aug 17, 2022
1 parent 675b6d4 commit 500332a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-ants-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Refactor static build config merge
26 changes: 4 additions & 22 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,16 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
const out = ssr ? opts.buildConfig.server : astroConfig.outDir;

const viteBuildConfig: ViteConfigWithSSR = {
...viteConfig,
logLevel: opts.viteConfig.logLevel ?? 'error',
mode: 'production',
css: viteConfig.css,
optimizeDeps: {
include: [...(viteConfig.optimizeDeps?.include ?? [])],
exclude: [...(viteConfig.optimizeDeps?.exclude ?? [])],
},
build: {
...viteConfig.build,
emptyOutDir: false,
manifest: false,
outDir: fileURLToPath(out),
rollupOptions: {
...viteConfig.build?.rollupOptions,
input: [],
output: {
format: 'esm',
Expand All @@ -138,7 +135,6 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
entryFileNames: opts.buildConfig.serverEntry,
},
},

ssr: true,
// must match an esbuild target
target: 'esnext',
Expand All @@ -163,12 +159,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
vitePluginAnalyzer(internals),
],
publicDir: ssr ? false : viteConfig.publicDir,
root: viteConfig.root,
envPrefix: 'PUBLIC_',
server: viteConfig.server,
base: astroConfig.base,
ssr: viteConfig.ssr,
resolve: viteConfig.resolve,
};

await runHookBuildSetup({
Expand All @@ -178,7 +169,6 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
target: 'server',
});

// TODO: use vite.mergeConfig() here?
return await vite.build(viteBuildConfig);
}

Expand All @@ -202,23 +192,19 @@ async function clientBuild(
return null;
}

// TODO: use vite.mergeConfig() here?
info(opts.logging, null, `\n${bgGreen(black(' building client '))}`);

const viteBuildConfig = {
...viteConfig,
logLevel: 'info',
mode: 'production',
css: viteConfig.css,
optimizeDeps: {
include: [...(viteConfig.optimizeDeps?.include ?? [])],
exclude: [...(viteConfig.optimizeDeps?.exclude ?? [])],
},
build: {
...viteConfig.build,
emptyOutDir: false,
minify: 'esbuild',
outDir: fileURLToPath(out),
rollupOptions: {
...viteConfig.build?.rollupOptions,
input: Array.from(input),
output: {
format: 'esm',
Expand All @@ -242,11 +228,7 @@ async function clientBuild(
}),
...(viteConfig.plugins || []),
],
publicDir: viteConfig.publicDir,
root: viteConfig.root,
envPrefix: 'PUBLIC_',
server: viteConfig.server,
base: astroConfig.base,
} as ViteConfigWithSSR;

await runHookBuildSetup({
Expand Down

0 comments on commit 500332a

Please sign in to comment.