这是我的VS Code的launch.json配置文件。
{
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/src/server/server.ts",
"cwd": "${workspaceRoot}",
"outDir": "${workspaceRoot}/build/server",
"sourceMaps": true,
"stopOnEntry": false,
"smartStep": true,
"runtimeArgs": ["--nolazy"]
}, {
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 5858,
"outFiles": [],
"sourceMaps": true
}]
}
我无法弄清楚为什么我只能在server.ts文件中放置断点,即使代码是使用sourcemaps编译的。
我使用gulp-typescript编译代码,如下所示
var tsProject = p.typescript.createProject(cfg.tsconfig);
return gulp.src(cfg.src)
.pipe(p.plumber({
errorHandler: p.notify.onError('Typescript SERVER error: <%= error.message %>')
}))
.pipe(p.sourcemaps.init({ loadMaps: true }))
.pipe(tsProject())
.pipe(p.sourcemaps.write('./'))
.pipe(gulp.dest(cfg.dest))
.pipe(p.notify({
title: 'Typescript SERVER',
message: 'Server compiled!',
onLast: true
}));
这是我的tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"sourceMap": true,
"noLib": false,
"outDir": "./../../build",
"rootDir": "./../"
},
"exclude": [
"./../client"
]
}