webpack.config.js 只需要注意加大加粗的地方。 var webpack = require("webpack"); var HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { entry:{ // 为每个入口都注入代理客户端 "index":[__dirname+'/src/js/index.js', 'webpack-dev-server/client?http://127.0.0.1:8080'] }, output:{ // 配合热编译服务器设置公共资源路径,但编译的时候需要移除。 publicPath : "http://127.0.0.1:8896/", path : __dirname + '/build/js', filename : '[name].js' }, plugins:[ new HtmlWebpackPlugin({ // 不能写为这种路径,但编译的时候需要写成这种路径 // filename : __dirname + "/build/spa.html", // 由于热编译启动的服务器,所以设置了publicPath,所以这里需要写为相对路径这样才可以访问localhost:port/spa.html