vue.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: '/eos',
  10. lintOnSave: false,
  11. outputDir: 'dist',
  12. productionSourceMap: false,
  13. configureWebpack: {
  14. performance: {
  15. maxAssetSize: 2000000,
  16. maxEntrypointSize: 2000000
  17. },
  18. output: {
  19. // 把子应用打包成 umd 库格式
  20. library: {
  21. type: 'umd',
  22. name: `${name}`
  23. },
  24. chunkLoadingGlobal: `webpackJsonp_${name}`
  25. }
  26. },
  27. devServer: {
  28. headers: {
  29. // 允许跨域访问子应用页面
  30. 'Access-Control-Allow-Origin': '*',
  31. },
  32. // 代理跨域的配置
  33. proxy: {
  34. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  35. '/api': {
  36. // target: 'http://192.168.3.51:18086', // 测试环境
  37. // target: 'http://124.71.68.31:50001',
  38. // target: 'http://192.168.1.139:18086', // 粟
  39. // target: 'http://192.168.1.132:18086', // 徐1
  40. // target: 'http://192.168.1.134:18086', //徐2
  41. target: 'http://192.168.1.105:18086',
  42. // target: 'http://192.168.1.103:18086',
  43. // target: 'http://192.168.1.251:18186',
  44. // target: 'http://192.168.1.105:18086',
  45. // target: 'http://192.168.1.114:18086',
  46. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  47. pathRewrite: {
  48. '^/api': ''
  49. }
  50. }
  51. }
  52. },
  53. chainWebpack(config) {
  54. config.plugins.delete('prefetch');
  55. // set svg-sprite-loader
  56. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  57. // config.module
  58. // .rule('icons')
  59. // .test(/\.svg$/)
  60. // .include.add(resolve('./src/icons'))
  61. // .end()
  62. // .use('svg-sprite-loader')
  63. // .loader('svg-sprite-loader')
  64. // .options({
  65. // symbolId: 'icon-[name]'
  66. // })
  67. // .end();
  68. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  69. config.module
  70. .rule('icons')
  71. .test(/\.svg$/)
  72. .include.add(resolve('src/icons'))
  73. .end()
  74. .use('svg-sprite-loader')
  75. .loader('svg-sprite-loader')
  76. .options({
  77. symbolId: 'icon-[name]'
  78. })
  79. .end();
  80. if (process.env.NODE_ENV !== 'development') {
  81. // gzip 压缩
  82. config.plugin('compressionPlugin').use(
  83. new CompressionWebpackPlugin({
  84. test: /\.(js|css|html)$/,
  85. threshold: 10240
  86. })
  87. );
  88. }
  89. },
  90. css: {
  91. loaderOptions: {
  92. sass: {
  93. sassOptions: {
  94. outputStyle: 'expanded',
  95. importer: transformElementScss()
  96. }
  97. }
  98. }
  99. }
  100. };