module.exports = { configureWebpack: { externals: { 'AMap': 'AMap' // 高德地图JS API } }, //路径前缀 publicPath: "/", lintOnSave: true, productionSourceMap: false, chainWebpack: (config) => { //gzip压缩 const CompressionWebpackPlugin = require('compression-webpack-plugin') if (process.env.NODE_ENV === 'production') { config.plugin('CompressionPlugin').use( new CompressionWebpackPlugin({ filename: '[path][base].gz[query]', // 压缩后的文件名(保持原文件名,后缀加.gz) algorithm: 'gzip', // 使用gzip压缩 test: /\.js$|\.css$/, // 匹配文件名 threshold: 10240, // 对超过10k的数据压缩 minRatio: 0.8, // 压缩率小于1才会压缩 deleteOriginalAssets: false // 是否删除未压缩的源文件,谨慎设置,如果希望提供非gzip的资源,可不设置或者设置为false(比如删除打包后的gz后还可以加载到原始资源文件) }) ) } // 开启压缩js代码 config.optimization.minimize(true) // 开启代码分割 config.optimization.splitChunks({ chunks: 'all', }); //忽略的打包文件 config.externals({ 'vue': 'Vue', 'vue-router': 'VueRouter', 'vuex': 'Vuex', 'axios': 'axios', 'element-ui': 'ELEMENT', }); const entry = config.entry('app'); entry.add('babel-polyfill').end(); entry.add('classlist-polyfill').end(); entry.add('@/mock').end(); }, css: { extract: { ignoreOrder: true } }, //开发模式反向代理配置,生产模式请使用Nginx部署并配置反向代理 devServer: { port: 1024, proxy: { '/api': { //本地服务接口地址 // target: 'http://192.168.3.64:1080', // target: 'http://192.168.8.106:1080', target: 'http://127.0.0.1:1080', // 打包地址 // target: 'http://121.37.83.47:10004',//服务器ip // target: 'http://trade.tubaosoft.com:10004',//服务器域名 ws: true, pathRewrite: { '^/api': '/' } } } } };