vue.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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: '/wms',
  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://192.168.3.51:18086', // 测试环境
  36. target: 'http://124.71.68.31:50001',
  37. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  38. pathRewrite: {
  39. '^/api': ''
  40. }
  41. }
  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. };