Skip to content

Commit 27fc294

Browse files
authored
feat: add node inspector (#12)
1 parent 2a2d777 commit 27fc294

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/cli.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ cli
1818
.option('-c, --config <path>', 'Use specified config file')
1919
.option('-m, --mode <mode>', 'Set env mode')
2020
.option('-w, --watch', 'Restart on file changes, similar to "nodemon"')
21+
.option('--inspect', 'Enable Node.js inspector')
22+
.option('--inspect-addr [host:port]', 'Enable Node.js inspector with specified address')
2123
.option('--script', 'Use vite-node as a script runner')
2224
.option('--options <options>', 'Use specified Vite server options')
2325
.option('-v, --version', 'Output the version number')
@@ -43,13 +45,21 @@ export interface CliOptions {
4345
'config'?: string
4446
'mode'?: string
4547
'watch'?: boolean
48+
'inspect'?: boolean
49+
'inspectAddr'?: string
4650
'options'?: ViteNodeServerOptionsCLI
4751
'version'?: boolean
4852
'help'?: boolean
4953
'--'?: string[]
5054
}
5155

5256
async function run(files: string[], options: CliOptions = {}) {
57+
if (options.inspect || options.inspectAddr) {
58+
const { open } = await import('node:inspector')
59+
const [host, port] = options.inspectAddr?.split(':') || ['127.0.0.1', '9229']
60+
open(Number(port), host, false)
61+
}
62+
5363
if (options.script) {
5464
files = [files[0]]
5565
options = {}

0 commit comments

Comments
 (0)