vue.config.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: '/wt',
  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. headers: {
  29. // 允许跨域访问子应用页面
  30. 'Access-Control-Allow-Origin': '*'
  31. },
  32. proxy: {
  33. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  34. '/api': {
  35. // target: 'http://124.71.68.31:50001', // 测试环境
  36. // target: 'http://124.71.68.31:50001',
  37. // target: 'http://192.168.1.105:18086',
  38. // target: 'http://192.168.1.251:18186',
  39. // target: 'http://192.168.1.251:18086',
  40. target: 'http://192.168.1.125:18086',
  41. // target: 'http://192.168.1.3:18086',
  42. // target: 'http://192.168.1.116:18086', // 赵沙金
  43. changeOrigin: true, // 只有这个值为true的情况下 s才表示开启跨域
  44. pathRewrite: {
  45. '^/api': ''
  46. }
  47. }
  48. }
  49. },
  50. chainWebpack(config) {
  51. config.plugins.delete('prefetch');
  52. // set svg-sprite-loader
  53. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  54. // config.module
  55. // .rule('icons')
  56. // .test(/\.svg$/)
  57. // .include.add(resolve('./src/icons'))
  58. // .end()
  59. // .use('svg-sprite-loader')
  60. // .loader('svg-sprite-loader')
  61. // .options({
  62. // symbolId: 'icon-[name]'
  63. // })
  64. // .end();
  65. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  66. config.module
  67. .rule('icons')
  68. .test(/\.svg$/)
  69. .include.add(resolve('src/icons'))
  70. .end()
  71. .use('svg-sprite-loader')
  72. .loader('svg-sprite-loader')
  73. .options({
  74. symbolId: 'icon-[name]'
  75. })
  76. .end();
  77. if (process.env.NODE_ENV !== 'development') {
  78. // gzip 压缩
  79. config.plugin('compressionPlugin').use(
  80. new CompressionWebpackPlugin({
  81. test: /\.(js|css|html)$/,
  82. threshold: 10240
  83. })
  84. );
  85. }
  86. },
  87. css: {
  88. loaderOptions: {
  89. sass: {
  90. sassOptions: {
  91. outputStyle: 'expanded',
  92. importer: transformElementScss()
  93. }
  94. }
  95. }
  96. }
  97. };