vue.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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: '/main-data',
  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. proxy: {
  29. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  30. '/api': {
  31. // target: 'http://192.168.1.3:18086',
  32. // target: 'http://192.168.1.158:18086',
  33. // target: 'http://192.168.1.176:18086',
  34. // target: 'http://192.168.1.125:18086',
  35. // target: 'http://192.168.1.251:51005',
  36. // target: 'http://192.168.1.251:18186',
  37. // target: 'http://192.168.1.251:18086',
  38. // target: 'http://192.168.1.251:18186',
  39. // target: 'http://192.168.1.3:18086',
  40. // target: 'http://192.168.1.251:18186', // 测试环境
  41. // target: 'http://192.168.1.251:18087',
  42. // target: 'http://192.168.1.116:18086',
  43. // target: 'http://192.168.1.125:18086',
  44. // target: 'http://192.168.1.11:18086', // 开发
  45. // target: 'http://192.168.1.116:18086', // 赵沙金
  46. target: 'http://aiot.zoomwin.com.cn:51001/api',
  47. // target: 'http://f222326r53.imwork.net',
  48. // target: 'http://aiot.zoomwin.com.cn:51005/api',
  49. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  50. pathRewrite: {
  51. '^/api': ''
  52. }
  53. }
  54. },
  55. headers: {
  56. 'Access-Control-Allow-Origin': '*'
  57. }
  58. },
  59. chainWebpack(config) {
  60. config.plugins.delete('prefetch');
  61. // set svg-sprite-loader
  62. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  63. // config.module
  64. // .rule('icons')
  65. // .test(/\.svg$/)
  66. // .include.add(resolve('./src/icons'))
  67. // .end()
  68. // .use('svg-sprite-loader')
  69. // .loader('svg-sprite-loader')
  70. // .options({
  71. // symbolId: 'icon-[name]'
  72. // })
  73. // .end();
  74. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  75. config.module
  76. .rule('icons')
  77. .test(/\.svg$/)
  78. .include.add(resolve('src/icons'))
  79. .end()
  80. .use('svg-sprite-loader')
  81. .loader('svg-sprite-loader')
  82. .options({
  83. symbolId: 'icon-[name]'
  84. })
  85. .end();
  86. if (process.env.NODE_ENV !== 'development') {
  87. // gzip 压缩
  88. config.plugin('compressionPlugin').use(
  89. new CompressionWebpackPlugin({
  90. test: /\.(js|css|html)$/,
  91. threshold: 10240
  92. })
  93. );
  94. }
  95. },
  96. css: {
  97. loaderOptions: {
  98. sass: {
  99. sassOptions: {
  100. outputStyle: 'expanded',
  101. importer: transformElementScss()
  102. }
  103. }
  104. }
  105. }
  106. };