vue.config.js 2.4 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: '/main-data',
  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://124.71.68.31:50001',
  32. // target: 'http://192.168.1.139:18086',
  33. // target: 'http://192.168.1.132:18086',
  34. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  35. pathRewrite: {
  36. '^/api': ''
  37. }
  38. }
  39. },
  40. headers: {
  41. 'Access-Control-Allow-Origin': '*'
  42. }
  43. },
  44. chainWebpack (config) {
  45. config.plugins.delete('prefetch');
  46. // set svg-sprite-loader
  47. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  48. // config.module
  49. // .rule('icons')
  50. // .test(/\.svg$/)
  51. // .include.add(resolve('./src/icons'))
  52. // .end()
  53. // .use('svg-sprite-loader')
  54. // .loader('svg-sprite-loader')
  55. // .options({
  56. // symbolId: 'icon-[name]'
  57. // })
  58. // .end();
  59. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  60. config.module
  61. .rule('icons')
  62. .test(/\.svg$/)
  63. .include.add(resolve('src/icons'))
  64. .end()
  65. .use('svg-sprite-loader')
  66. .loader('svg-sprite-loader')
  67. .options({
  68. symbolId: 'icon-[name]'
  69. })
  70. .end();
  71. if (process.env.NODE_ENV !== 'development') {
  72. // gzip 压缩
  73. config.plugin('compressionPlugin').use(
  74. new CompressionWebpackPlugin({
  75. test: /\.(js|css|html)$/,
  76. threshold: 10240
  77. })
  78. );
  79. }
  80. },
  81. css: {
  82. loaderOptions: {
  83. sass: {
  84. sassOptions: {
  85. outputStyle: 'expanded',
  86. importer: transformElementScss()
  87. }
  88. }
  89. }
  90. }
  91. };