javascript - 如何使用 webpack 调试 Node apollo 服务器

标签 javascript node.js debugging webpack apollo-server

我正在尝试调试 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/

相关文章:

c++ - 搜索具有特定签名调用的函数?

python - 跟踪 Python 导入

javascript - 将二进制资源文件加载到 Chrome 应用程序中

javascript - 如何使用可变版本参数(可变参数)创建外部javascript链接

php - 如何正确使用 JSON.stringify 和 json_decode()

javascript - 如何使用node js中的express通过server.js文件将照片渲染到网页

javascript - Forge Autodesk 模型的变换矩阵

javascript - $(this.element) 未定义,不明白为什么

javascript - 如何在 html 文件中包含 nodejs 模块?

visual-studio-2008 - 如何重定向 Visual Studio 调试器的输出?