vue.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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: '/aps',
  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.1.210:86/',
  32. // target: 'http://192.168.1.103:18086',
  33. // target: 'http://192.168.1.158:18086',
  34. // target: 'http://192.168.158:18086',
  35. // target: 'http://192.168.1.251:18086',
  36. // target: 'http://192.168.1.144:18086',
  37. // target: 'http://192.168.1.211:18086',
  38. target: 'http://192.168.1.102:18086',
  39. // target: 'http://192.168.1.125:18086',
  40. // target: 'http://192.168.1.116:18086',
  41. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  42. pathRewrite: {
  43. '^/api': ''
  44. }
  45. }
  46. },
  47. headers: {
  48. 'Access-Control-Allow-Origin': '*'
  49. }
  50. },
  51. chainWebpack(config) {
  52. config.plugins.delete('prefetch');
  53. // set svg-sprite-loader
  54. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  55. // config.module
  56. // .rule('icons')
  57. // .test(/\.svg$/)
  58. // .include.add(resolve('./src/icons'))
  59. // .end()
  60. // .use('svg-sprite-loader')
  61. // .loader('svg-sprite-loader')
  62. // .options({
  63. // symbolId: 'icon-[name]'
  64. // })
  65. // .end();
  66. config.module
  67. .rule('file-loader')
  68. .test(/\.(pdf|docx|doc|xlsx|xls|mp4)$/)
  69. .use('file-loader?name=[path][name].[ext]')
  70. .loader('file-loader')
  71. .end();
  72. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  73. config.module
  74. .rule('icons')
  75. .test(/\.svg$/)
  76. .include.add(resolve('src/icons'))
  77. .end()
  78. .use('svg-sprite-loader')
  79. .loader('svg-sprite-loader')
  80. .options({
  81. symbolId: 'icon-[name]'
  82. })
  83. .end();
  84. if (process.env.NODE_ENV !== 'development') {
  85. // gzip 压缩
  86. config.plugin('compressionPlugin').use(
  87. new CompressionWebpackPlugin({
  88. test: /\.(js|css|html)$/,
  89. threshold: 10240
  90. })
  91. );
  92. }
  93. },
  94. css: {
  95. loaderOptions: {
  96. sass: {
  97. sassOptions: {
  98. outputStyle: 'expanded',
  99. importer: transformElementScss()
  100. }
  101. }
  102. }
  103. }
  104. };