vue.config.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. // webpack5 默认不打包 node 内置模块:sax 在模块加载阶段就会 require('stream'),
  21. // 若把 stream 置空(fallback: { stream: false }),require 不会抛错但取到的
  22. // .Stream 是 undefined,sax 执行 Stream.prototype 时会报
  23. // “Cannot read properties of undefined (reading 'prototype')”,导致应用启动即崩。
  24. // 这里改为指向一个最小实现的桩模块,既消掉构建告警,也保证运行期不报错。
  25. alias: {
  26. stream: path.resolve(__dirname, 'build/stream-stub.js')
  27. }
  28. },
  29. output: {
  30. // 把子应用打包成 umd 库格式
  31. library: {
  32. type: 'umd',
  33. name: `${name}`
  34. },
  35. chunkLoadingGlobal: `webpackJsonp_${name}`
  36. }
  37. },
  38. devServer: {
  39. headers: {
  40. // 允许跨域访问子应用页面
  41. 'Access-Control-Allow-Origin': '*'
  42. },
  43. // 前端路由为 history 模式,接口与预览服务不能回退到 index.html
  44. historyApiFallback: {
  45. index: path.posix.join(publicPath, 'index.html'),
  46. htmlAcceptHeaders: ['text/html'],
  47. rewrites: [
  48. {
  49. from: /^\/(api|kkfile)(\/|$)/,
  50. to: (context) => context.parsedUrl.pathname
  51. }
  52. ]
  53. },
  54. // 代理跨域的配置
  55. proxy: {
  56. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  57. '/api': {
  58. // target: 'http://192.168.1.251:18086', //开发
  59. // target: 'http://192.168.1.251:18186', //测试
  60. // target: 'http://192.168.1.23:18086',//罗
  61. // target: 'http://192.168.1.144:18086',//付
  62. target: 'http://192.168.1.102:18086',
  63. // target: 'http://aiot.zoomwin.com.cn:51001/api',
  64. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  65. pathRewrite: {
  66. '^/api': ''
  67. }
  68. },
  69. // kkFileView 在线预览服务(word、excel 等文档需要转换后才能预览)
  70. '/kkfile': {
  71. target: 'http://aiot.zoomwin.com.cn:51001',
  72. changeOrigin: true,
  73. pathRewrite: {
  74. '^/kkfile': '/kkfile'
  75. }
  76. }
  77. }
  78. },
  79. chainWebpack(config) {
  80. config.plugins.delete('prefetch');
  81. // set svg-sprite-loader
  82. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  83. // config.module
  84. // .rule('icons')
  85. // .test(/\.svg$/)
  86. // .include.add(resolve('./src/icons'))
  87. // .end()
  88. // .use('svg-sprite-loader')
  89. // .loader('svg-sprite-loader')
  90. // .options({
  91. // symbolId: 'icon-[name]'
  92. // })
  93. // .end();
  94. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  95. config.module
  96. .rule('icons')
  97. .test(/\.svg$/)
  98. .include.add(resolve('src/icons'))
  99. .end()
  100. .use('svg-sprite-loader')
  101. .loader('svg-sprite-loader')
  102. .options({
  103. symbolId: 'icon-[name]'
  104. })
  105. .end();
  106. if (process.env.NODE_ENV !== 'development') {
  107. // gzip 压缩
  108. config.plugin('compressionPlugin').use(
  109. new CompressionWebpackPlugin({
  110. test: /\.(js|css|html)$/,
  111. threshold: 10240
  112. })
  113. );
  114. }
  115. },
  116. css: {
  117. loaderOptions: {
  118. sass: {
  119. sassOptions: {
  120. outputStyle: 'expanded',
  121. importer: transformElementScss()
  122. }
  123. }
  124. }
  125. }
  126. };