最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I debug webpack-dev-server's built-in express server in VS code? - Stack Overflow

programmeradmin2浏览0评论

I've got a configuration file where in the webpack devServer config Withing the webpack devServer config, I have defined a express middleware function:

devServer: {
    before(app){
        init(app);
    },
    ...
}

Where init is a function of the form:

init(app){
    app.get('/endpoint', (req,res,next)=> {...;debugger; next();});
    ...
}

How can I debug this webpack-dev-server code?

I would prefer if I could debug it straight in VSCode, but I'm happy to use in-browser debugging if necessary.

I've got a configuration file where in the webpack devServer config Withing the webpack devServer config, I have defined a express middleware function:

devServer: {
    before(app){
        init(app);
    },
    ...
}

Where init is a function of the form:

init(app){
    app.get('/endpoint', (req,res,next)=> {...;debugger; next();});
    ...
}

How can I debug this webpack-dev-server code?

I would prefer if I could debug it straight in VSCode, but I'm happy to use in-browser debugging if necessary.

Share edited Feb 26, 2018 at 23:27 keithlee96 asked Feb 26, 2018 at 6:22 keithlee96keithlee96 1,9642 gold badges13 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

As it turns out, there was a pretty simple way to debug webpack-dev-server in VSCode. Just debug the executable as a node file!

Here was my launch.json:

{
    "type": "node",
    "request": "launch",
    "name":"launch webpack-dev-server",
    "program": "${workspaceFolder}/node_modules/webpack-dev-server/bin/webpack-dev-server.js",
    "args": ["--progress", "--inline", "--config", "build/webpack.dev.conf.js"]
}

Note: For anyone who copies this, you will have to change the webpack configuration file path arg to whatever it is on your machine.

You can debug webpack build scripts in the exact same way:

{
    "type": "node",
    "request": "launch",
    "name":"launch webpack",
    "program": "${workspaceFolder}/node_modules/webpack/bin/webpack.js",
    "args": ["--progress", "--config", "build/webpack.prod.conf.js"]
},

Note: this debugs the build / server itself. If you want to debug the output files, you need to also attach a debugger to the url. You can do that using using something like the chrome debugger.

发布评论

评论列表(0)

  1. 暂无评论