vue.config.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. const CompressionWebpackPlugin = require('compression-webpack-plugin');
  2. const { transformElementScss } = require('ele-admin/lib/utils/dynamic-theme');
  3. const path = require('path');
  4. function resolve(dir) {
  5. return path.join(__dirname, dir);
  6. }
  7. module.exports = {
  8. lintOnSave: false,
  9. productionSourceMap: false,
  10. configureWebpack: {
  11. performance: {
  12. maxAssetSize: 2000000,
  13. maxEntrypointSize: 2000000
  14. }
  15. },
  16. devServer: {
  17. // 代理跨域的配置
  18. proxy: {
  19. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  20. '/api': {
  21. // target: 'http://192.168.3.51:86', // 测试
  22. // target: 'http://192.168.3.35:8080', // kang杨威
  23. // target: 'http://192.168.3.25:8080', // 黄峥嵘
  24. // target: 'http://192.168.3.41:8080', // 何江鹏
  25. target: 'http://192.168.3.33:8080', // 谢一平
  26. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  27. pathRewrite: {
  28. '^/api': ''
  29. }
  30. }
  31. }
  32. },
  33. chainWebpack(config) {
  34. config.plugins.delete('prefetch');
  35. // set svg-sprite-loader
  36. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  37. // config.module
  38. // .rule('icons')
  39. // .test(/\.svg$/)
  40. // .include.add(resolve('./src/icons'))
  41. // .end()
  42. // .use('svg-sprite-loader')
  43. // .loader('svg-sprite-loader')
  44. // .options({
  45. // symbolId: 'icon-[name]'
  46. // })
  47. // .end();
  48. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  49. config.module
  50. .rule('icons')
  51. .test(/\.svg$/)
  52. .include.add(resolve('src/icons'))
  53. .end()
  54. .use('svg-sprite-loader')
  55. .loader('svg-sprite-loader')
  56. .options({
  57. symbolId: 'icon-[name]'
  58. })
  59. .end();
  60. if (process.env.NODE_ENV !== 'development') {
  61. // gzip 压缩
  62. config.plugin('compressionPlugin').use(
  63. new CompressionWebpackPlugin({
  64. test: /\.(js|css|html)$/,
  65. threshold: 10240
  66. })
  67. );
  68. }
  69. },
  70. css: {
  71. loaderOptions: {
  72. sass: {
  73. sassOptions: {
  74. outputStyle: 'expanded',
  75. importer: transformElementScss()
  76. }
  77. }
  78. }
  79. }
  80. };