|
1 | | -import path from 'path' |
2 | | -import type { Plugin, UserConfig } from 'vite' |
| 1 | +import type { Plugin, UserConfig } from "vite"; |
3 | 2 |
|
4 | 3 | export interface ClientBuildOptions { |
5 | | - outDir?: string |
| 4 | + outDir?: string; // Client output directory |
| 5 | + emptyOutDir?: boolean; // Whether to empty the output directory before build |
6 | 6 | } |
7 | 7 |
|
8 | | -export const defaultClientBuildOptions: Required<ClientBuildOptions> = { |
9 | | - outDir: 'dist', |
10 | | -} |
| 8 | +export const defaultClientBuildOptions: Partial<ClientBuildOptions> = { |
| 9 | + outDir: "public", |
| 10 | + emptyOutDir: true, |
| 11 | +}; |
11 | 12 |
|
12 | 13 | export function clientBuild(options?: ClientBuildOptions): Plugin { |
13 | | - const mergedOptions = { ...defaultClientBuildOptions, ...options } |
14 | | - |
15 | | - return { |
16 | | - name: 'vite-plugin-srvx-client-build', |
| 14 | + const mergedOptions = { ...defaultClientBuildOptions, ...options }; |
17 | 15 |
|
18 | | - // Only apply during client builds (not server builds) |
19 | | - apply(_config, { command, mode }) { |
20 | | - return command === 'build' && mode !== 'server' |
21 | | - }, |
| 16 | + return { |
| 17 | + name: "vite-plugin-srvx-client-build", |
22 | 18 |
|
23 | | - config(): UserConfig { |
24 | | - // Output to 'dist/public' (or custom outDir/public) |
25 | | - const clientOutDir = path.join(mergedOptions.outDir, 'public') |
| 19 | + // Only apply during client builds (not server builds) |
| 20 | + apply(_config, { command, mode }) { |
| 21 | + return command === "build" && mode !== "server"; |
| 22 | + }, |
26 | 23 |
|
27 | | - return { |
28 | | - build: { |
29 | | - outDir: clientOutDir, |
30 | | - }, |
31 | | - } |
32 | | - }, |
33 | | - } |
| 24 | + config(): UserConfig { |
| 25 | + return { |
| 26 | + build: { |
| 27 | + outDir: mergedOptions.outDir, |
| 28 | + emptyOutDir: mergedOptions.emptyOutDir, |
| 29 | + }, |
| 30 | + }; |
| 31 | + }, |
| 32 | + }; |
34 | 33 | } |
0 commit comments