'use strict' // Template version: 1.3.1 // see http://vuejs-templates.github.io/webpack for documentation. const path = require('path') module.exports = { dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', // Various Dev Server settings host: '0.0.0.0', // can be overwritten by process.env.HOST port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined autoOpenBrowser: false, errorOverlay: true, notifyOnErrors: true, poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- proxyTable: { // 这里配置 '/api' 就等价于 target , 你在链接里访问 /api === http://localhost:54321 '/api': { // 请求的代称,写在Axios里的BaseUrl target: 'http://localhost:8088/spring', // 真实请求的URL 后台接口域名 ws: true, // //如果要代理 websockets,配置这个参数 secure: false, // 如果是https接口,需要配置这个参数 changeOrigin: true, // 允许跨域 pathRewrite: { //替换,通配/api的替换成对应字符 /* 重写路径, 当我们在浏览器中看到请求的地址为:http://localhost:8080/api/core/getData/userInfo 时 实际上访问的地址是 http://localhost:8088/spring/core/getData/userInfo, 因为重写了/api */ '^/api': '' //当你的接口中没有/api字眼时,采用这种,直接替换成空即可 // '^/api': '/api' 当你的接口中刚好有/api 时,采用这种方式 } }, '/api2': { target: 'http://10.10.4.121:8070', // secure: true, // 如果是 https ,需要开启这个选项 changeOrigin: true, // 是否是跨域请求?肯定是啊,不跨域就没有必要配置这个proxyTable了. pathRewrite: { // 重写路径 例如浏览器请求地址http://localhost:12345/xxx,实际请求的是你代理的地址:http:xxx/11111 // 这里是追加链接,比如真是接口里包含了 /api,就需要这样配置. '^/api': '/api', // 和下边两种写法,因人而异根据需求。 // 等价于 /api + /api == http://localhost:54321/api // 如果写为 '^/api' : '/' // 等价于 /api + / == http://localhost:54321/ // 这里的 /api == http://localhost:54321 } // 首先,在ProxyTable模块中设置了‘/api’,target中设置服务器地址,也就是接口的开头那段地址,例如http://localhost:54321, // 然后我们在调用接口的时候,就可以全局使用/api,这时候/api的作用就相当于http://localhost:54321, // 比如接口的地址是http://localhost:54321/api/json.data,我们就可以使用/api/json.data // 那pathRewrite是用来干嘛的呢,这里的作用,相当于是替代/api, // 如果接口中是没有api的,那就直接置空, // 如果接口中有api,那就得写成{^/api:/api},可以理解为一个重定向或者重新赋值的功能 } }, /** * Source Maps */ // https://webpack.js.org/configuration/devtool/#development devtool: 'cheap-module-eval-source-map', // If you have problems debugging vue-files in devtools, // set this to false - it *may* help // https://vue-loader.vuejs.org/en/options.html#cachebusting cacheBusting: true, cssSourceMap: true, }, build: { // Template for index.html index: path.resolve(__dirname, '../SWZJXT/index.html'), // Paths assetsRoot: path.resolve(__dirname, '../SWZJXT'), assetsSubDirectory: './static', assetsPublicPath: './', /** * Source Maps */ productionSourceMap: true,//浏览器源代码可以看到 // productionSourceMap: false, // https://webpack.js.org/configuration/devtool/#production devtool: '#source-map', // Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. // Before setting to `true`, make sure to: // npm install --save-dev compression-webpack-plugin productionGzip: false, productionGzipExtensions: ['js', 'css'], // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report } }