vue.config.js中的一些配置:
const webpack = require("webpack"); const CompressionPlugin = require("compression-webpack-plugin"); // npm install --save-dev compression-webpack-plugin module.exports = { publicPath: "./", productionSourceMap: false, //这里关闭Source Maps configureWebpack: { plugins: [ // 配置jQuery new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery", "windows.jQuery": "jquery", }), // 开启gzip压缩 new CompressionPlugin({ algorithm: 'gzip', test: /\.(js|css)$/,// 匹配文件名 threshold: 10240, // 对超过10k的数据压缩 deleteOriginalAssets: false, // 不删除源文件 minRatio: 0.8 // 压缩比 }) ], }, // 打包分析 chainWebpack: (config) => { if (process.env.use_analyzer) { // 分析 config .plugin("webpack-bundle-analyzer") .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin); } }, devServer: { open: true, host: '0.0.0.0', port: 8080, https: false, hotOnly: false, disableHostCheck: true, //配置代理 // proxy: null proxy: { //以'/api'开头的接口会转接到下面的target的ip '/api/': { target: 'http://192.168.1.164/', // target host secure: false, changeOrigin: true, // needed for virtual hosted sites ws: false, // proxy websockets pathRewrite: { //路径重写 '^/api/': '', // rewrite path }, logLevel: "debug" }, } } };