vscode下ts-node传入cli参数

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 using require('ts-node').register({ /* options */ }). You can also use file shortcuts - node -r ts-node/register or node -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 with node -r ts-node/register instead of the ts-node CLI.

然后给出段不明配置文件

Visual Studio Code

Create a new node.js configuration, add -r ts-node/register to node args and move the program to the args list (so VS Code doesn't look for outFiles).

{
    "type""node",
    "request""launch",
    "name""Launch Program",
    "runtimeArgs"[
        "-r",
        "ts-node/register"
    ],
    "args"[
        "${workspaceFolder}/index.ts"
    ]
}

不知该放那里,说得不清楚。

参考这个vscode 调试node之npm与nodemon,原来是vscode的launch.json

 

猜你喜欢

转载自www.cnblogs.com/xuanmanstein/p/9946629.html