我正在尝试调试 Express apollo 服务器应用程序,但我正在努力找出问题所在。我已经构建了一个启用了源映射并将加载器选项调试设置为 true 的 Web 包构建。
我的 npm 脚本输出我的 webpack 构建和调试器的 url
"debug": "node --inspect ./node_modules/.bin/webpack --config ./webpack.dev.js"
我通过 chrome://inspect
进入调试器我可以查看我的代码,但是当我通过 http://localhost:8080/graphiql
发送请求时调试器内没有任何反应,请求正常进行。
这是我的 webpack 配置
const webpack = require("webpack");
const path = require("path");
const nodeExternals = require("webpack-node-externals");
const StartServerPlugin = require("start-server-webpack-plugin");
module.exports = {
entry: ["./server.js"],
watch: true,
mode: "development",
target: "node",
node: {
__filename: true,
__dirname: true
},
externals: [nodeExternals({ whitelist: ["webpack/hot/poll?1000"] })],
module: {
rules: [
{
test: /\.js?$/,
use: [
{
loader: "babel-loader",
options: {
babelrc: false,
presets: [["env", { modules: false }], "stage-0"],
plugins: ["transform-regenerator", "transform-runtime"]
}
}
],
exclude: /node_modules/
}
]
},
plugins: [
new StartServerPlugin("server.js"),
new webpack.NamedModulesPlugin(),
new webpack.LoaderOptionsPlugin({
debug: true
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.SourceMapDevToolPlugin({
filename: '[name].js.map'
}),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
"process.env": { BUILD_TARGET: JSON.stringify("server") }
})
],
output: { path: path.join(__dirname, "dist"), filename: "server.js" }
};
我的问题是我需要经历任何额外的步骤才能使其与 graphql 服务器一起工作,我是否正确设置了源映射?
感谢任何帮助。
最佳答案
我通过使用 nodemon 并同时在 parrell 中运行 webpack 配置来修复此问题
https://github.com/remy/nodemon
https://www.npmjs.com/package/concurrently
"debug": "同时\"webpack --config ./webpack.dev.js\"\"nodemon --inspect=9229 ./dist/server.js\""
我还添加了
devtool: 'eval-source-map'
添加到我的 webpack 配置以启用源映射。
我还从 webpack 配置中删除了启动服务器插件,本质上只是让 webpack 构建并提供 nodemon 服务。
关于javascript - 如何使用 webpack 调试 Node apollo 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50778040/