vue.config.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  2. const productionGzipExtensions = ['js', 'css', 'ttf', 'woff', 'woff2']
  3. module.exports = {
  4. // 如果您不需要生产时的源映射,那么将此设置为false可以加速生产构建
  5. productionSourceMap: false,
  6. // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
  7. // assetsDir: 'static',
  8. configureWebpack: config => {
  9. config.resolve.alias['vue$'] = 'vue/dist/vue.esm.js';
  10. if (process.env.NODE_ENV === 'production') {
  11. // 生产环境
  12. config.plugins.push(
  13. new CompressionWebpackPlugin({
  14. filename: '[path].gz[query]', // 提示示compression-webpack-plugin@3.0.0的话asset改为filename
  15. algorithm: 'gzip',
  16. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  17. threshold: 4096,
  18. minRatio: 0.8
  19. })
  20. );
  21. } else {
  22. // 开发环境
  23. }
  24. },
  25. chainWebpack: config => {
  26. // 移除 prefetch 插件
  27. config.plugins.delete('prefetch');
  28. },
  29. parallel: require('os').cpus().length > 1, // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用,仅作用于生产构建。
  30. devServer: {
  31. //关闭ip检查 (用于会议签到机接口调用)
  32. disableHostCheck: true,
  33. // 设置代理
  34. hot: true, //热加载
  35. host: '0.0.0.0', //ip地址
  36. port: 8081, //端口
  37. https: false, //false关闭https,true为开启
  38. open: true, //自动打开浏览器
  39. proxy: {
  40. '/api/nationregioncomittee-service': {
  41. // target: "http://192.168.1.79:7055",
  42. target: "http://127.0.0.1:7055",
  43. changeOrigin: true,
  44. pathRewrite: {
  45. '^/api/nationregioncomittee-service': '/'
  46. }
  47. },
  48. '/api': {
  49. target: 'http://172.16.1.159:7000/',
  50. // target: 'http://localhost:7000/',
  51. //本地
  52. // target: 'http://10.0.1.160:7000/',
  53. // target: 'http://192.168.1.116:7000/', //设置你调用的接口域名和端口号 别忘了加http
  54. // target: 'http://localhost:7000/', //设置你调用的接口域名和端口号 别忘了加http
  55. //target: 'http://192.168.1.247:7000/', //设置你调用的接口域名和端口号 别忘了加http
  56. // 如果要代理 websockets
  57. // ws: true,
  58. changeOrigin: true,
  59. pathRewrite: {
  60. '^/api': '/' //这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可
  61. }
  62. }
  63. }
  64. }
  65. }