通过chrome调试
node --inspect-brk ./node_modules/webpack-cli/bin/cli.js
通过执行命令调试
- 打开工程目录,点击调试按钮,再点击小齿轮的配置按钮系统就会生成 launch.json 配置文件
- 修改好了以后直接点击 F5 就可以启动调试
.vscode\launch.json
{"version": "0.2.0","configurations": [{"type": "node","request": "launch","name": "debug webpack","cwd": "${workspaceFolder}","program": "${workspaceFolder}/node_modules/webpack-cli/bin/cli.js"}]}
debugger.js
const webpack = require("webpack");const webpackOptions = require("./webpack.config");const compiler = webpack(webpackOptions);//4.执行对象的run方法开始执行编译compiler.run((err, stats) => {console.log(err);console.log(stats.toJson({assets: true,chunks: true,modules: true,entries: true,}));});
调试webpack-cli源码
git clone https://github.com/webpack/webpack.gitgit reset --hard vx.x.xyarnyarn linkgit clone https://github.com/webpack/webpack-cli.gitgit reset --hard webpack-cli@x.x.xcd packages\webpack-cliyarn link webpackyarn link
yarn link webpackyarn link webpack-cliyarn unlink webpackyarn unlink webpack-cli
