vue.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  2. const productionGzipExtensions = ['js', 'css']
  3. module.exports = {
  4. publicPath:'/',
  5. // 如果您不需要生产时的源映射,那么将此设置为false可以加速生产构建
  6. productionSourceMap: false,
  7. // 放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
  8. // assetsDir: 'static',
  9. configureWebpack: config => {
  10. config.resolve.alias['vue$'] = 'vue/dist/vue.esm.js';
  11. if (process.env.NODE_ENV === 'production') {
  12. // 生产环境
  13. config.plugins.push(
  14. new CompressionWebpackPlugin({
  15. filename: '[path].gz[query]', // 提示示compression-webpack-plugin@3.0.0的话asset改为filename
  16. algorithm: 'gzip',
  17. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  18. threshold: 10240,
  19. minRatio: 0.8
  20. })
  21. );
  22. } else {
  23. // 开发环境
  24. }
  25. },
  26. chainWebpack: config => {
  27. // 移除 prefetch 插件
  28. config.plugins.delete('prefetch');
  29. },
  30. parallel: require('os').cpus().length > 1, // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用,仅作用于生产构建。
  31. devServer: {
  32. // 设置代理
  33. hot: true, //热加载
  34. host: '0.0.0.0', //ip地址
  35. port: 8080, //端口
  36. https: false, //false关闭https,true为开启
  37. open: true, //自动打开浏览器
  38. proxy: {
  39. '/api': {
  40. // target: 'http://10.0.1.64:7000/',
  41. // target: 'http://10.0.1.87:7000/',
  42. // target: 'http://10.1.207.81:7000/',
  43. // target: 'http://localhost:7000/',
  44. target: 'http://172.16.1.159:7000/',
  45. // target: 'https://www.geidcp.com/api/',
  46. // target: 'http://localhost:7000/',
  47. // target: 'http://172.16.1.159:7000/',
  48. // target: 'http://localhost:7000/',
  49. // target: 'http://172.16.1.159:7000/',
  50. // target: 'http://10.0.1.161:7000/',
  51. // 如果要代理 websockets
  52. ws: true,
  53. changeOrigin: true,
  54. pathRewrite: {
  55. '^/api': '/' //这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可
  56. }
  57. },
  58. '/captchas/get': {
  59. // target: 'http://10.1.2.152:7001/',
  60. target: 'http://172.16.1.159:7000/',
  61. // target: 'http://localhost:7012/',
  62. changeOrigin: true,
  63. pathRewrite: {
  64. '^/captchas/get': '/captchas/get'
  65. }
  66. },
  67. '/captchas/check': {
  68. // target: 'http://10.1.2.152:7001/',
  69. target: 'http://172.16.1.159:7000/',
  70. // target: 'http://localhost:7012/',
  71. changeOrigin: true,
  72. pathRewrite: {
  73. '^/captchas/check': '/captchas/check'
  74. }
  75. },
  76. '/captcha/tmp': {
  77. // target: 'http://10.1.2.152:7001/',
  78. target: 'http://172.16.1.159:7000/',
  79. // target: 'http://localhost:7012/',
  80. changeOrigin: true,
  81. pathRewrite: {
  82. '^/captcha/tmp': '/captcha/tmp'
  83. }
  84. },
  85. '/captcha': {
  86. // target: 'http://10.1.2.152:7001/',
  87. target: 'http://172.16.1.159:7000/',
  88. // target: 'http://localhost:7012/',
  89. // 如果要代理 websockets
  90. // ws: true,
  91. changeOrigin: true,
  92. pathRewrite: {
  93. '^/captcha': '/captcha/template'
  94. }
  95. }
  96. }
  97. },
  98. }