【发布时间】:2019-04-02 17:02:08
【问题描述】:
我有一个 nodejs express 应用程序,我正在尝试与 webpack 4(加上 babel 7.1.0)捆绑。我遵循了这两篇文章中的一些设置:
- Webpack Javascript Bundling for Both Front-end and Back-end (nodejs)
- Creating a server bundle with Webpack for universal rendering
捆绑后我可以构建和运行服务器,但我希望能够使用 VS Code 的调试环境对其进行调试。
我尝试了以下 webpack 和 vscode 配置的组合,但它没有设置断点,也没有让我进入代码。
.vscode/launch.json
{
"type": "node",
"request": "launch",
"name": "bundle-server.js",
"program": "${workspaceFolder}\\bundle-server.js",
"sourceMaps": true,
"smartStep": true,
}
webpack-server.config.js
const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
target: "node",
entry: "./server.js",
output: {
path: path.resolve(__dirname, "./"),
filename: "bundle-server.js",
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: "babel-loader"
}
],
},
externals: [nodeExternals()],
devtool: 'inline-source-map',
};
我错过了什么?甚至可以直接从 VSCode 调试吗?我希望能够跳过原始源文件,以便快速进行调试-编辑-重新运行循环。
似乎与此有关:Debug webpack bundled node ts with Visual Studio Code。
【问题讨论】:
-
在 Node 进程已经运行后附加到它可能会更容易。详情请见code.visualstudio.com/docs/nodejs/…。
标签: javascript node.js webpack visual-studio-code