vue.config.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: '/eam',
  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://124.71.68.31:50001',
  33. // target: 'http://192.168.1.139:18086', // 粟
  34. // target: 'http://192.168.1.132:18086', // 徐
  35. target: 'http://192.168.1.110:18086', //本
  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. };