vue.config.js 3.3 KB

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