快轉到主要內容
  1. 文章/

Visual Studio Code (launch with babel, mocha)

·1 分鐘

Visual Studio Code 是個不錯的編輯器,不過設定上,還是有很多需要手動的動作
特此記錄

launch.json 範例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Run app",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "${workspaceRoot}/node_modules/babel-cli/bin/babel-node.js",
      "program": "${workspaceRoot}/src/index.js",
      "stopOnEntry": false,
      "args": [
        "--presets es2015,stage-0"
      ],
      "env": {
        "NODE_ENV": "development"
      }
    },
    {
      "name": "Run mocha",
      "type": "node",
      "program": "${workspaceRoot}/node_modules/mocha/bin/mocha",
      "stopOnEntry": false,
      "args": [
        "--compilers", 
        "js:babel-register",
        "test/**/*.js"
      ],
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": null,
      "env": {
        "NODE_ENV": "production"
      }
    }
  ]
}