vue.config.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. 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. // 代理跨域的配置
  28. proxy: {
  29. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  30. '/api': {
  31. target: 'http://192.168.3.51:18086', // 测试
  32. // target: 'http://192.168.3.35:8080', // kang杨威
  33. // target: 'http://192.168.3.25:8080', // 黄峥嵘
  34. // target: 'http://192.168.3.41:8080', // 何江鹏
  35. // target: 'http://192.168.3.33:8080', // 谢一平
  36. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  37. pathRewrite: {
  38. '^/api': ''
  39. }
  40. }
  41. }
  42. },
  43. chainWebpack (config) {
  44. config.plugins.delete('prefetch');
  45. // set svg-sprite-loader
  46. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  47. // config.module
  48. // .rule('icons')
  49. // .test(/\.svg$/)
  50. // .include.add(resolve('./src/icons'))
  51. // .end()
  52. // .use('svg-sprite-loader')
  53. // .loader('svg-sprite-loader')
  54. // .options({
  55. // symbolId: 'icon-[name]'
  56. // })
  57. // .end();
  58. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  59. config.module
  60. .rule('icons')
  61. .test(/\.svg$/)
  62. .include.add(resolve('src/icons'))
  63. .end()
  64. .use('svg-sprite-loader')
  65. .loader('svg-sprite-loader')
  66. .options({
  67. symbolId: 'icon-[name]'
  68. })
  69. .end();
  70. if (process.env.NODE_ENV !== 'development') {
  71. // gzip 压缩
  72. config.plugin('compressionPlugin').use(
  73. new CompressionWebpackPlugin({
  74. test: /\.(js|css|html)$/,
  75. threshold: 10240
  76. })
  77. );
  78. }
  79. },
  80. css: {
  81. loaderOptions: {
  82. sass: {
  83. sassOptions: {
  84. outputStyle: 'expanded',
  85. importer: transformElementScss()
  86. }
  87. }
  88. }
  89. }
  90. };