vue.config.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const CompressionWebpackPlugin = require('compression-webpack-plugin');
  2. const {
  3. transformElementScss
  4. } = require('ele-admin/lib/utils/dynamic-theme');
  5. const path = require('path');
  6. const {
  7. name
  8. } = require('./package.json');
  9. function resolve(dir) {
  10. return path.join(__dirname, dir);
  11. }
  12. module.exports = {
  13. publicPath: '/wt',
  14. lintOnSave: false,
  15. productionSourceMap: false,
  16. configureWebpack: {
  17. performance: {
  18. maxAssetSize: 2000000,
  19. maxEntrypointSize: 2000000
  20. },
  21. output: {
  22. // 把子应用打包成 umd 库格式
  23. library: {
  24. type: 'umd',
  25. name: `${name}`
  26. },
  27. chunkLoadingGlobal: `webpackJsonp_${name}`
  28. }
  29. },
  30. devServer: {
  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.116:18086',
  38. // target: 'http://192.168.1.125:18086',
  39. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  40. pathRewrite: {
  41. '^/api': ''
  42. }
  43. }
  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. };