Skip to content

Commit 74dabf9

Browse files
authored
fix: output files to correct directory (#4)
1 parent 6c02feb commit 74dabf9

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

examples/vercel/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ dist/
1818
# OS
1919
.DS_Store
2020
.vercel
21+
public

src/client-build.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
import path from 'path'
2-
import type { Plugin, UserConfig } from 'vite'
1+
import type { Plugin, UserConfig } from "vite";
32

43
export interface ClientBuildOptions {
5-
outDir?: string
4+
outDir?: string; // Client output directory
5+
emptyOutDir?: boolean; // Whether to empty the output directory before build
66
}
77

8-
export const defaultClientBuildOptions: Required<ClientBuildOptions> = {
9-
outDir: 'dist',
10-
}
8+
export const defaultClientBuildOptions: Partial<ClientBuildOptions> = {
9+
outDir: "public",
10+
emptyOutDir: true,
11+
};
1112

1213
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 };
1715

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",
2218

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+
},
2623

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+
};
3433
}

src/srvx.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ export interface SrvxOptions extends DevServerOptions {
88
outDir?: string;
99
serverOutFile?: string;
1010
framework?: "vercel"; // Target framework for deployment
11+
// Client build options
12+
clientOutDir?: string; // Client output directory (default: "public")
13+
clientEmptyOutDir?: boolean; // Whether to empty the client output directory before build (default: true)
1114
}
1215

1316
export const defaultSrvxOptions: Partial<SrvxOptions> = {
1417
entry: "./src/server.ts",
1518
outDir: "dist",
19+
clientOutDir: "public",
1620
serverOutFile: "server.js",
1721
};
1822

@@ -30,7 +34,8 @@ export function srvx(options?: SrvxOptions): Plugin[] {
3034

3135
// Client build plugin
3236
clientBuild({
33-
outDir: mergedOptions.outDir,
37+
outDir: mergedOptions.clientOutDir,
38+
emptyOutDir: mergedOptions.clientEmptyOutDir,
3439
}),
3540

3641
// Server build plugin

0 commit comments

Comments
 (0)