vue.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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: '/mes',
  10. lintOnSave: false,
  11. productionSourceMap: false,
  12. configureWebpack: {
  13. devtool: 'source-map',
  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. // 代理跨域的配置
  29. proxy: {
  30. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  31. '/api': {
  32. // target: 'http://124.71.68.31:50001',
  33. // target: 'http://192.168.1.116:18086',
  34. // target: 'http://192.168.1.251:18086',
  35. // target: 'http://192.168.1.103:18086',192.168.1.116
  36. target: 'http://192.168.1.125:18086',
  37. // target: 'http://192.168.1.116:18086',
  38. // target: 'http://192.168.1.144:18086',
  39. // target: 'http://192.168.1.30:18086',
  40. // target: 'http://192.168.1.211:18086',
  41. // target: 'http://192.168.1.33:18086',
  42. // target: 'http://192.168.1.251:18186',
  43. // target: 'http://192.168.1.251:18087',
  44. // target: 'http://192.168.1.116:18086',
  45. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  46. pathRewrite: {
  47. '^/api': ''
  48. }
  49. }
  50. }
  51. },
  52. chainWebpack(config) {
  53. config.plugins.delete('prefetch');
  54. // set svg-sprite-loader
  55. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  56. // config.module
  57. // .rule('icons')
  58. // .test(/\.svg$/)
  59. // .include.add(resolve('./src/icons'))
  60. // .end()
  61. // .use('svg-sprite-loader')
  62. // .loader('svg-sprite-loader')
  63. // .options({
  64. // symbolId: 'icon-[name]'
  65. // })
  66. // .end();
  67. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  68. config.module
  69. .rule('icons')
  70. .test(/\.svg$/)
  71. .include.add(resolve('src/icons'))
  72. .end()
  73. .use('svg-sprite-loader')
  74. .loader('svg-sprite-loader')
  75. .options({
  76. symbolId: 'icon-[name]'
  77. })
  78. .end();
  79. if (process.env.NODE_ENV !== 'development') {
  80. // gzip 压缩
  81. config.plugin('compressionPlugin').use(
  82. new CompressionWebpackPlugin({
  83. test: /\.(js|css|html)$/,
  84. threshold: 10240
  85. })
  86. );
  87. }
  88. },
  89. css: {
  90. loaderOptions: {
  91. sass: {
  92. sassOptions: {
  93. outputStyle: 'expanded',
  94. importer: transformElementScss()
  95. }
  96. }
  97. }
  98. }
  99. };