vue.config.js 2.2 KB

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