vue.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. const publicPath = '/ehs';
  9. module.exports = {
  10. publicPath,
  11. lintOnSave: false,
  12. outputDir: 'dist',
  13. productionSourceMap: false,
  14. configureWebpack: {
  15. performance: {
  16. maxAssetSize: 2000000,
  17. maxEntrypointSize: 2000000
  18. },
  19. resolve: {
  20. // xlsx 依赖的 sax 里有一行 require('stream')(仅流式解析用,浏览器走不到),
  21. // webpack5 默认不打包 node 内置模块,显式置空消掉构建警告
  22. fallback: {
  23. stream: false
  24. }
  25. },
  26. output: {
  27. // 把子应用打包成 umd 库格式
  28. library: {
  29. type: 'umd',
  30. name: `${name}`
  31. },
  32. chunkLoadingGlobal: `webpackJsonp_${name}`
  33. }
  34. },
  35. devServer: {
  36. headers: {
  37. // 允许跨域访问子应用页面
  38. 'Access-Control-Allow-Origin': '*'
  39. },
  40. // 前端路由为 history 模式,接口与预览服务不能回退到 index.html
  41. historyApiFallback: {
  42. index: path.posix.join(publicPath, 'index.html'),
  43. htmlAcceptHeaders: ['text/html'],
  44. rewrites: [
  45. {
  46. from: /^\/(api|kkfile)(\/|$)/,
  47. to: (context) => context.parsedUrl.pathname
  48. }
  49. ]
  50. },
  51. // 代理跨域的配置
  52. proxy: {
  53. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  54. '/api': {
  55. // target: 'http://192.168.1.251:18086', //开发
  56. // target: 'http://192.168.1.251:18186', //测试
  57. // target: 'http://192.168.1.23:18086',//罗
  58. // target: 'http://192.168.1.144:18086',//付
  59. target: 'http://192.168.1.102:18086',
  60. // target: 'http://aiot.zoomwin.com.cn:51001/api',
  61. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  62. pathRewrite: {
  63. '^/api': ''
  64. }
  65. },
  66. // kkFileView 在线预览服务(word、excel 等文档需要转换后才能预览)
  67. '/kkfile': {
  68. target: 'http://aiot.zoomwin.com.cn:51001',
  69. changeOrigin: true,
  70. pathRewrite: {
  71. '^/kkfile': '/kkfile'
  72. }
  73. }
  74. }
  75. },
  76. chainWebpack(config) {
  77. config.plugins.delete('prefetch');
  78. // set svg-sprite-loader
  79. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  80. // config.module
  81. // .rule('icons')
  82. // .test(/\.svg$/)
  83. // .include.add(resolve('./src/icons'))
  84. // .end()
  85. // .use('svg-sprite-loader')
  86. // .loader('svg-sprite-loader')
  87. // .options({
  88. // symbolId: 'icon-[name]'
  89. // })
  90. // .end();
  91. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  92. config.module
  93. .rule('icons')
  94. .test(/\.svg$/)
  95. .include.add(resolve('src/icons'))
  96. .end()
  97. .use('svg-sprite-loader')
  98. .loader('svg-sprite-loader')
  99. .options({
  100. symbolId: 'icon-[name]'
  101. })
  102. .end();
  103. if (process.env.NODE_ENV !== 'development') {
  104. // gzip 压缩
  105. config.plugin('compressionPlugin').use(
  106. new CompressionWebpackPlugin({
  107. test: /\.(js|css|html)$/,
  108. threshold: 10240
  109. })
  110. );
  111. }
  112. },
  113. css: {
  114. loaderOptions: {
  115. sass: {
  116. sassOptions: {
  117. outputStyle: 'expanded',
  118. importer: transformElementScss()
  119. }
  120. }
  121. }
  122. }
  123. };