ts-node写ts,启动时习惯在package.json里写
"scripts": { "build-ts": "tsc", "start": "ts-node src/server.ts", "start:dev": "nodemon", "serve": "node dist/server.js", "test": "mocha --require ts-node/register test/**/*.ts", "build_browser_dev": "browserify ./src/page.js -o ./static/bundle.js -t [ babelify --presets[env]]" },
但是当希望启动时传入命令行参数时,ts-node没法接受命令行参数
https://www.npmjs.com/package/ts-node
Programmatic
You can require
ts-node
and register the loader for future requires by usingrequire('ts-node').register({ /* options */ })
. You can also use file shortcuts -node -r ts-node/register
ornode -r ts-node/register/transpile-only
- depending on your preferences.Note: If you need to use advanced node.js CLI arguments (e.g.
--inspect
), use them withnode -r ts-node/register
instead of thets-node
CLI.
然后给出段不明配置文件
Visual Studio Code
Create a new node.js configuration, add
-r ts-node/register
to node args and move theprogram
to theargs
list (so VS Code doesn't look foroutFiles
).
{
}
不知该放那里,说得不清楚。
参考这个vscode 调试node之npm与nodemon,原来是vscode的launch.json