开发环境下,启动一个web服务,模拟用户从浏览器访问我们的web服务。
npm install webpack-dev-serveer html-webpack-plugin
const HtmlWebpackPlugin = require('html-webpack-plugin')const path = require('path')module.exports = {mode: "development",entry: './app.js',output: {publicPath: "/",clean: true},module: {rules: [{test: /\.js$/,exclude: /node_modules/,use: {loader: "babel-loader",options: {presets: ['@babel/preset-env']}}}]},devtool: 'source-map',devServer: {static: path.resolve(__dirname, './dist'),// 是否在服务器端进行压缩compress: true,// https: true,// http2: true// 服务的端口号// port:3000,host:'0.0.0.0',// 服务器传给浏览器的信息headers: {'X-Access-Token': 'test123'},// 跨域proxy: {// 请求/api这个接口就会自动变成请求http://localhost:9000/api'/api': 'http://localhost:9000'},historyApiFallback:true,},plugins: [new HtmlWebpackPlugin()]}
