1. 修改配置,方便调试
module.exports = {
devtool: 'eval-source-map',
entry: __dirname + "/app/main.js", output: { path: __dirname + "/public", filename: "bundle.js" } }
2.调试时实时更新代码
npm install --save-dev webpack-dev-server
module.exports = { devtool: 'eval-source-map', entry: __dirname + "/app/main.js", output: { path: __dirname + "/public", filename: "bundle.js" }, devServer: { contentBase: "./public",//本地服务器所加载的页面所在的目录 historyApiFallback: true,//不跳转 inline: true//实时刷新 } }
"scripts": { "test": "echo "Error: no test specified" && exit 1", "start": "webpack", "server": "webpack-dev-server --open" },
在终端中输入npm run server
即可在本地的8080
端口查看结果