vue.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. const CompressionWebpackPlugin = require('compression-webpack-plugin');
  2. const { transformElementScss } = require('ele-admin/lib/utils/dynamic-theme');
  3. const path = require('path');
  4. const { name } = require('./package.json');
  5. function resolve(dir) {
  6. return path.join(__dirname, dir);
  7. }
  8. module.exports = {
  9. publicPath: '/wt',
  10. lintOnSave: false,
  11. productionSourceMap: false,
  12. configureWebpack: {
  13. performance: {
  14. maxAssetSize: 2000000,
  15. maxEntrypointSize: 2000000
  16. },
  17. output: {
  18. // 把子应用打包成 umd 库格式
  19. library: {
  20. type: 'umd',
  21. name: `${name}`
  22. },
  23. chunkLoadingGlobal: `webpackJsonp_${name}`
  24. }
  25. },
  26. devServer: {
  27. // 代理跨域的配置
  28. headers: {
  29. // 允许跨域访问子应用页面
  30. 'Access-Control-Allow-Origin': '*'
  31. },
  32. proxy: {
  33. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  34. '/api': {
  35. // target: 'http://124.71.68.31:50001', // 测试环境
  36. // target: 'http://124.71.68.31:50001',
  37. // target: 'http://192.168.1.105:18086',
  38. // target: 'http://localhost:18086',
  39. // target: 'http://192.168.1.116:18086',
  40. // target: 'http://192.168.1.3:18086',
  41. // target: 'http://192.168.1.251:18186',
  42. // target: 'http://192.168.1.251:18086',
  43. // target: 'http://192.168.1.3:18086',
  44. // target: 'http://aiot.zoomwin.com.cn:51001/api',
  45. // target: 'http://192.168.1.3:18086',
  46. // target: 'http://192.168.1.147:18086', // 陈兵
  47. // target: 'http://192.168.1.116:18086', // 赵沙金
  48. // target: 'http://192.168.1.113:18086', // 郭丹
  49. target: 'http://192.168.1.102:18086', // 吴志豪
  50. changeOrigin: true, // 只有这个值为true的情况下 s才表示开启跨域
  51. pathRewrite: {
  52. '^/api': ''
  53. }
  54. },
  55. // kkFileView 在线预览服务代理(让本地像测试环境一样能加载 /kkfile/onlinePreview)
  56. '/kkfile': {
  57. target: 'http://aiot.zoomwin.com.cn:51001',
  58. changeOrigin: true,
  59. pathRewrite: { '^/kkfile': '/kkfile' }
  60. }
  61. }
  62. },
  63. chainWebpack(config) {
  64. config.plugins.delete('prefetch');
  65. // set svg-sprite-loader
  66. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  67. // config.module
  68. // .rule('icons')
  69. // .test(/\.svg$/)
  70. // .include.add(resolve('./src/icons'))
  71. // .end()
  72. // .use('svg-sprite-loader')
  73. // .loader('svg-sprite-loader')
  74. // .options({
  75. // symbolId: 'icon-[name]'
  76. // })
  77. // .end();
  78. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  79. config.module
  80. .rule('icons')
  81. .test(/\.svg$/)
  82. .include.add(resolve('src/icons'))
  83. .end()
  84. .use('svg-sprite-loader')
  85. .loader('svg-sprite-loader')
  86. .options({
  87. symbolId: 'icon-[name]'
  88. })
  89. .end();
  90. if (process.env.NODE_ENV !== 'development') {
  91. // gzip 压缩
  92. config.plugin('compressionPlugin').use(
  93. new CompressionWebpackPlugin({
  94. test: /\.(js|css|html)$/,
  95. threshold: 10240
  96. })
  97. );
  98. }
  99. },
  100. css: {
  101. loaderOptions: {
  102. sass: {
  103. sassOptions: {
  104. outputStyle: 'expanded',
  105. importer: transformElementScss()
  106. }
  107. }
  108. }
  109. }
  110. };