Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/vercel/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ dist/
# OS
.DS_Store
.vercel
public
47 changes: 23 additions & 24 deletions src/client-build.ts
Original file line number Diff line number Diff line change
@@ -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<ClientBuildOptions> = {
outDir: 'dist',
}
export const defaultClientBuildOptions: Partial<ClientBuildOptions> = {
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,
},
};
},
};
}
7 changes: 6 additions & 1 deletion src/srvx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SrvxOptions> = {
entry: "./src/server.ts",
outDir: "dist",
clientOutDir: "public",
serverOutFile: "server.js",
};

Expand All @@ -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
Expand Down
Loading