vue.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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://192.168.1.125: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.116:18086', // 赵沙金
  47. changeOrigin: true, // 只有这个值为true的情况下 s才表示开启跨域
  48. pathRewrite: {
  49. '^/api': ''
  50. }
  51. }
  52. }
  53. },
  54. chainWebpack(config) {
  55. config.plugins.delete('prefetch');
  56. // set svg-sprite-loader
  57. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  58. // config.module
  59. // .rule('icons')
  60. // .test(/\.svg$/)
  61. // .include.add(resolve('./src/icons'))
  62. // .end()
  63. // .use('svg-sprite-loader')
  64. // .loader('svg-sprite-loader')
  65. // .options({
  66. // symbolId: 'icon-[name]'
  67. // })
  68. // .end();
  69. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  70. config.module
  71. .rule('icons')
  72. .test(/\.svg$/)
  73. .include.add(resolve('src/icons'))
  74. .end()
  75. .use('svg-sprite-loader')
  76. .loader('svg-sprite-loader')
  77. .options({
  78. symbolId: 'icon-[name]'
  79. })
  80. .end();
  81. if (process.env.NODE_ENV !== 'development') {
  82. // gzip 压缩
  83. config.plugin('compressionPlugin').use(
  84. new CompressionWebpackPlugin({
  85. test: /\.(js|css|html)$/,
  86. threshold: 10240
  87. })
  88. );
  89. }
  90. },
  91. css: {
  92. loaderOptions: {
  93. sass: {
  94. sassOptions: {
  95. outputStyle: 'expanded',
  96. importer: transformElementScss()
  97. }
  98. }
  99. }
  100. }
  101. };