pnpm dev command starts a development server with Hot Module Replacement (HMR) support. When you modify code, changes are instantly reflected without restarting the server.
Basic Usage
- Auto-restart: Automatic server restart on code changes
- TypeScript support: Run .ts files directly
- Source map support: Accurate line numbers on errors
- Keyboard shortcuts: Shortcuts for quick actions
Subcommands
You can run API and Web separately.| Command | Description |
|---|---|
pnpm dev | Integrated API + Web dev server (default) |
pnpm dev api | API-only dev server (integrated web server disabled) |
pnpm dev web | Standalone Vite dev server |
How It Works
pnpm dev internally uses the following tools:
| Tool | Role | Provider |
|---|---|---|
@sonamu-kit/hmr-runner | HMR execution engine | Sonamu |
@sonamu-kit/ts-loader | TypeScript loader | Sonamu |
@sonamu-kit/hmr-hook | HMR hook | Sonamu |
Execution Process
- Execute
src/index.tsas entry point - Transform and execute TypeScript files immediately
- Detect file changes
- Replace only changed modules (HMR)
- Full restart only when necessary
Keyboard Shortcuts
You can use the following shortcuts while the development server is running:| Shortcut | Function | Description |
|---|---|---|
r | Restart | Manually restart the server |
c | Clear screen | Clear the terminal screen |
f | Force restart | Delete sonamu.lock file and restart |
Enter | Test | Key binding test |
Ctrl+F Ctrl+F | Update | Git pull, install packages, build, and restart |
Shortcut Usage Examples
Server restart:Environment Variables
The development server automatically sets the following environment variables:| Variable | Value | Description |
|---|---|---|
NODE_ENV | development | Development mode indicator |
HOT | yes | HMR activation flag |
API_ROOT_PATH | Project path | HMR root directory |
How HMR Works
Cases That Auto-restart
The server automatically restarts when modifying these files:- Entity files (
*.entity.ts) - Model files (
*.model.ts) - Config files (
sonamu.config.ts) - Migration files
Cases Reflected Instantly (HMR)
Changes to these files are reflected instantly without server restart:- General business logic
- Utility functions
- Service layer
Troubleshooting
Server Wonβt Start
Problem: Port already in useHMR Not Working
Problem: Code changes not reflected Solution:TypeScript Errors
Problem: Server wonβt start due to type errors Solution:Practical Tips
1. Fast Development Cycle
Modify code and test immediately:2. Check Logs
Development server outputs all logs to console:3. Debugging
Source maps are enabled for accurate line numbers:Differences from Production
| Feature | Development Server | Production |
|---|---|---|
| HMR | β Enabled | β Disabled |
| TypeScript | Immediate execution | Compilation needed |
| Source maps | Original files | Compressed files |
| Performance | Slower | Faster |
| Error display | Detailed | Brief |