vue.config.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const path = require('path');
  2. const CompressionPlugin = require('compression-webpack-plugin');
  3. module.exports = {
  4. publicPath: `/${process.env.VUE_APP_ROUTER}`,
  5. // 打包文件
  6. outputDir: `${process.env.VUE_APP_ROUTER}`,
  7. productionSourceMap: false,
  8. configureWebpack: (config) => {
  9. Object.assign(config, {
  10. // 开发生产共同配置
  11. resolve: {
  12. extensions: ['.js', '.json', '.vue'],
  13. alias: {
  14. '@': path.resolve(__dirname, './src'),
  15. '@c': path.resolve(__dirname, './src/components'),
  16. '@a': path.resolve(__dirname, './src/assets'),
  17. },
  18. },
  19. });
  20. if (process.env.NODE_ENV === 'production') {
  21. //生产环境
  22. config.plugins.push(
  23. new CompressionPlugin({
  24. /* [file]被替换为原始资产文件名。
  25. [path]替换为原始资产的路径。
  26. [dir]替换为原始资产的目录。
  27. [name]被替换为原始资产的文件名。
  28. [ext]替换为原始资产的扩展名。
  29. [query]被查询替换。*/
  30. filename: '[path].gz[query]',
  31. //压缩算法
  32. algorithm: 'gzip',
  33. //匹配文件
  34. test: /\.js$|\.css$|\.html$/,
  35. //压缩超过此大小的文件,以字节为单位
  36. threshold: 10240,
  37. minRatio: 0.8,
  38. //删除原始文件只保留压缩后的文件
  39. //deleteOriginalAssets: false
  40. })
  41. );
  42. config.externals = {
  43. vue: 'Vue',
  44. 'vue-router': 'VueRouter',
  45. vuex: 'Vuex',
  46. axios: 'axios',
  47. moment: 'moment',
  48. lodash: '_',
  49. vant: 'vant',
  50. };
  51. }
  52. },
  53. devServer: {
  54. port: '9801',
  55. //api地址前缀
  56. proxy: {
  57. '/files': {
  58. target: 'http://broadcast.waityou24.cn',
  59. },
  60. '/wxgateway': {
  61. target: 'http://broadcast.waityou24.cn', //http://192.168.1.19:9101
  62. changeOrigin: true,
  63. ws: false,
  64. },
  65. '/api': {
  66. target: 'http://192.168.1.19:11001', //http://192.168.1.19:9101
  67. changeOrigin: true,
  68. ws: false,
  69. },
  70. },
  71. },
  72. };