Webpack Dev Server(Webpack 开发服务器), 详情查看:https://www.npmjs.com/package/webpack-dev-server \

安装

npm i webpack-dev-server -D # 或者 npm i webpack-dev-server -g

运⾏

# webpack 4 webpack-dev-server … # webpack 5 webpack server … Webpack Dev Server 将打包内容放到内存中(⽽⾮磁盘),内存的读写性能远⼤于磁盘,因此

Webpack Dev Server 的热更新效率⼤于 browser-sync

运⾏ 并 ⾃动打开浏览器 webpack server —open

为 Webpack Dev Server 指定配置

devServer: { // 项⽬构建后路径 contentBase:resolve(__dirname,‘output’), // 启动gzip压缩 compress:true, // 端⼝号 port:3000, // 开启热更新 hot: true, // 开启接⼝代理 proxy: { ‘/api’: { // http://localhost:8080/api/users -> https://api.github.com/api/users target: https://api.github.com, // http://localhost:8080/api/users -> https://api.github.com/users pathRewrite: { ‘^/api’: ‘’ }, // 不能使⽤ localhost:8080 作为请求 GitHub 的主机名 changeOrigin: true } } },

更多配置详情:https://webpack.docschina.org/configuration/dev-server