vue.config.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. lintOnSave: false,
  10. productionSourceMap: false,
  11. configureWebpack: {
  12. performance: {
  13. maxAssetSize: 2000000,
  14. maxEntrypointSize: 2000000
  15. },
  16. output: {
  17. // 把子应用打包成 umd 库格式
  18. library: {
  19. type: 'umd',
  20. name: `${name}`
  21. },
  22. chunkLoadingGlobal: `webpackJsonp_${name}`
  23. }
  24. },
  25. devServer: {
  26. // 代理跨域的配置
  27. proxy: {
  28. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  29. '/api': {
  30. // target: 'http://192.168.3.51:86', // 测试
  31. // target: 'http://192.168.3.35:8080', // kang杨威
  32. // target: 'http://192.168.3.25:8080', // 黄峥嵘
  33. // target: 'http://192.168.3.41:8080', // 何江鹏
  34. target: 'http://192.168.3.33:8080', // 谢一平
  35. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  36. pathRewrite: {
  37. '^/api': ''
  38. }
  39. }
  40. },
  41. headers: {
  42. 'Access-Control-Allow-Origin': '*'
  43. }
  44. },
  45. chainWebpack (config) {
  46. config.plugins.delete('prefetch');
  47. // set svg-sprite-loader
  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. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  61. config.module
  62. .rule('icons')
  63. .test(/\.svg$/)
  64. .include.add(resolve('src/icons'))
  65. .end()
  66. .use('svg-sprite-loader')
  67. .loader('svg-sprite-loader')
  68. .options({
  69. symbolId: 'icon-[name]'
  70. })
  71. .end();
  72. if (process.env.NODE_ENV !== 'development') {
  73. // gzip 压缩
  74. config.plugin('compressionPlugin').use(
  75. new CompressionWebpackPlugin({
  76. test: /\.(js|css|html)$/,
  77. threshold: 10240
  78. })
  79. );
  80. }
  81. },
  82. css: {
  83. loaderOptions: {
  84. sass: {
  85. sassOptions: {
  86. outputStyle: 'expanded',
  87. importer: transformElementScss()
  88. }
  89. }
  90. }
  91. }
  92. };