diff --git a/examples/vercel/.gitignore b/examples/vercel/.gitignore index 8cf80cd..553dd86 100644 --- a/examples/vercel/.gitignore +++ b/examples/vercel/.gitignore @@ -18,3 +18,4 @@ dist/ # OS .DS_Store .vercel +public diff --git a/src/client-build.ts b/src/client-build.ts index 10d129b..0f0605b 100644 --- a/src/client-build.ts +++ b/src/client-build.ts @@ -1,34 +1,33 @@ -import path from 'path' -import type { Plugin, UserConfig } from 'vite' +import type { Plugin, UserConfig } from "vite"; export interface ClientBuildOptions { - outDir?: string + outDir?: string; // Client output directory + emptyOutDir?: boolean; // Whether to empty the output directory before build } -export const defaultClientBuildOptions: Required = { - outDir: 'dist', -} +export const defaultClientBuildOptions: Partial = { + outDir: "public", + emptyOutDir: true, +}; export function clientBuild(options?: ClientBuildOptions): Plugin { - const mergedOptions = { ...defaultClientBuildOptions, ...options } - - return { - name: 'vite-plugin-srvx-client-build', + const mergedOptions = { ...defaultClientBuildOptions, ...options }; - // Only apply during client builds (not server builds) - apply(_config, { command, mode }) { - return command === 'build' && mode !== 'server' - }, + return { + name: "vite-plugin-srvx-client-build", - config(): UserConfig { - // Output to 'dist/public' (or custom outDir/public) - const clientOutDir = path.join(mergedOptions.outDir, 'public') + // Only apply during client builds (not server builds) + apply(_config, { command, mode }) { + return command === "build" && mode !== "server"; + }, - return { - build: { - outDir: clientOutDir, - }, - } - }, - } + config(): UserConfig { + return { + build: { + outDir: mergedOptions.outDir, + emptyOutDir: mergedOptions.emptyOutDir, + }, + }; + }, + }; } diff --git a/src/srvx.ts b/src/srvx.ts index 88417cd..62b1f11 100644 --- a/src/srvx.ts +++ b/src/srvx.ts @@ -8,11 +8,15 @@ export interface SrvxOptions extends DevServerOptions { outDir?: string; serverOutFile?: string; framework?: "vercel"; // Target framework for deployment + // Client build options + clientOutDir?: string; // Client output directory (default: "public") + clientEmptyOutDir?: boolean; // Whether to empty the client output directory before build (default: true) } export const defaultSrvxOptions: Partial = { entry: "./src/server.ts", outDir: "dist", + clientOutDir: "public", serverOutFile: "server.js", }; @@ -30,7 +34,8 @@ export function srvx(options?: SrvxOptions): Plugin[] { // Client build plugin clientBuild({ - outDir: mergedOptions.outDir, + outDir: mergedOptions.clientOutDir, + emptyOutDir: mergedOptions.clientEmptyOutDir, }), // Server build plugin