vue.config.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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: '/pro',
  10. lintOnSave: false,
  11. productionSourceMap: false,
  12. configureWebpack: {
  13. devtool: 'source-map',
  14. performance: {
  15. maxAssetSize: 2000000,
  16. maxEntrypointSize: 2000000
  17. },
  18. output: {
  19. // 把子应用打包成 umd 库格式
  20. library: {
  21. type: 'umd',
  22. name: `${name}`
  23. },
  24. chunkLoadingGlobal: `webpackJsonp_${name}`
  25. }
  26. },
  27. devServer: {
  28. // 代理跨域的配置
  29. proxy: {
  30. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  31. '/api': {
  32. target: 'http://192.168.1.251:18086',//开发
  33. // target: 'http://192.168.1.251:18186',//测试
  34. // target: 'http://192.168.1.144:18086',//付莉
  35. // target: 'http://192.168.1.158:18086',//罗华林
  36. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  37. pathRewrite: {
  38. '^/api': ''
  39. }
  40. }
  41. },
  42. headers: {
  43. 'Access-Control-Allow-Origin': '*'
  44. }
  45. },
  46. chainWebpack(config) {
  47. config.plugins.delete('prefetch');
  48. // set svg-sprite-loader
  49. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  50. // config.module
  51. // .rule('icons')
  52. // .test(/\.svg$/)
  53. // .include.add(resolve('./src/icons'))
  54. // .end()
  55. // .use('svg-sprite-loader')
  56. // .loader('svg-sprite-loader')
  57. // .options({
  58. // symbolId: 'icon-[name]'
  59. // })
  60. // .end();
  61. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  62. config.module
  63. .rule('icons')
  64. .test(/\.svg$/)
  65. .include.add(resolve('src/icons'))
  66. .end()
  67. .use('svg-sprite-loader')
  68. .loader('svg-sprite-loader')
  69. .options({
  70. symbolId: 'icon-[name]'
  71. })
  72. .end();
  73. if (process.env.NODE_ENV !== 'development') {
  74. // gzip 压缩
  75. config.plugin('compressionPlugin').use(
  76. new CompressionWebpackPlugin({
  77. test: /\.(js|css|html)$/,
  78. threshold: 10240
  79. })
  80. );
  81. }
  82. },
  83. css: {
  84. loaderOptions: {
  85. sass: {
  86. sassOptions: {
  87. outputStyle: 'expanded',
  88. importer: transformElementScss()
  89. }
  90. }
  91. }
  92. }
  93. };