vue.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const CompressionWebpackPlugin = require('compression-webpack-plugin');
  2. const {
  3. transformElementScss
  4. } = require('ele-admin/lib/utils/dynamic-theme');
  5. const path = require('path');
  6. const {
  7. name
  8. } = require('./package.json');
  9. function resolve(dir) {
  10. return path.join(__dirname, dir);
  11. }
  12. module.exports = {
  13. publicPath: '/main-data',
  14. lintOnSave: false,
  15. productionSourceMap: false,
  16. configureWebpack: {
  17. performance: {
  18. maxAssetSize: 2000000,
  19. maxEntrypointSize: 2000000
  20. },
  21. output: {
  22. // 把子应用打包成 umd 库格式
  23. library: {
  24. type: 'umd',
  25. name: `${name}`
  26. },
  27. chunkLoadingGlobal: `webpackJsonp_${name}`
  28. }
  29. },
  30. devServer: {
  31. // 代理跨域的配置
  32. proxy: {
  33. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  34. '/api': {
  35. target: 'http://192.168.1.251:18086',
  36. // target: 'http://192.168.1.158:18086',
  37. // target: 'http://192.168.1.176:18086',
  38. // target: 'http://192.168.1.251:18086',
  39. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  40. pathRewrite: {
  41. '^/api': ''
  42. }
  43. }
  44. },
  45. headers: {
  46. 'Access-Control-Allow-Origin': '*'
  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. };