vue.config.js 2.4 KB

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