vue.config.js 3.3 KB

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