Skip to content

Commit c848124

Browse files
committed
feat: basic dev command
1 parent 4fadf93 commit c848124

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

examples/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "module",
55
"scripts": {
66
"build": "rs build",
7-
"dev": "rs dev --open",
7+
"dev": "rs dev",
88
"preview": "rs preview"
99
},
1010
"dependencies": {

src/cli/commands.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cac from 'cac';
22
import { logger } from '@rsbuild/core';
33
import { initRsbuild } from './rsbuild.js';
4-
import type { BuildOptions } from './types.js';
4+
import type { BuildOptions, DevOptions } from './types.js';
55

66
declare global {
77
const RSTACK_VERSION: string;
@@ -12,6 +12,22 @@ export function setupCommands(): void {
1212

1313
cli.version(RSTACK_VERSION);
1414

15+
cli.command('dev', 'Start the Rsbuild dev server').action(async (options: DevOptions) => {
16+
try {
17+
const rsbuild = await initRsbuild({
18+
options,
19+
});
20+
if (!rsbuild) {
21+
return;
22+
}
23+
await rsbuild.startDevServer();
24+
} catch (err) {
25+
logger.error('Failed to start dev server.');
26+
logger.error(err);
27+
process.exit(1);
28+
}
29+
});
30+
1531
cli
1632
.command('build', 'Run Rsbuild to build the app for production')
1733
.option('-w, --watch', 'Enable watch mode to automatically rebuild on file changes')

src/cli/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ export type BuildOptions = {
66
root?: string;
77
watch?: boolean;
88
};
9+
10+
export type DevOptions = RsbuildCommonOptions;

0 commit comments

Comments
 (0)