vue.config.js 2.7 KB

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