vue.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. 'use strict'
  2. const path = require('path')
  3. const px2rem = require('postcss-px2rem')
  4. // 配置基本大小
  5. const postcss = px2rem({
  6. // 基准大小 baseSize,需要和rem.js中相同
  7. remUnit: 80
  8. })
  9. function resolve(dir) {
  10. return path.join(__dirname, dir)
  11. }
  12. const name = '重卡换电智能站控系统'
  13. module.exports = {
  14. publicPath: "/",
  15. outputDir: 'dist',
  16. assetsDir: 'static',
  17. lintOnSave: false,
  18. css: {
  19. loaderOptions: {
  20. postcss: {
  21. plugins: [
  22. postcss
  23. ]
  24. }
  25. }
  26. },
  27. productionSourceMap: false,
  28. devServer: {
  29. host: 'localhost',
  30. port: 808,
  31. open: true,
  32. overlay: {
  33. warning: false,
  34. error: true,
  35. },
  36. proxy: {
  37. '/api': {
  38. // target: `http://192.168.3.177:8080`,
  39. target: `http://zk.li-ai.com.cn:8080`,
  40. secure: false,
  41. ws: true,
  42. changeOrigin: true,
  43. },
  44. '/ws': {
  45. // target: `ws://192.168.3.177:8080/ws`,
  46. target: `ws://zk.li-ai.com.cn:8080/ws`,
  47. secure: false,
  48. ws: true,
  49. changeOrigin: true,
  50. },
  51. '/video':{
  52. // target: `ws://192.168.3.177:8082/`,
  53. target: `ws://192.168.3.177:8082/ws`,
  54. secure: false,
  55. ws: true,
  56. changeOrigin: true,
  57. }
  58. },
  59. },
  60. configureWebpack: {
  61. name: name,
  62. resolve: {
  63. alias: {
  64. '@': resolve('src')
  65. }
  66. }
  67. },
  68. chainWebpack(config) {
  69. config.plugin('preload').tap(() => [
  70. {
  71. rel: 'preload',
  72. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  73. include: 'initial'
  74. }
  75. ])
  76. config.plugins.delete('prefetch')
  77. config.module
  78. .rule('svg')
  79. .exclude.add(resolve('src/icons'))
  80. .end()
  81. config.module
  82. .rule('icons')
  83. .test(/\.svg$/)
  84. .include.add(resolve('src/icons'))
  85. .end()
  86. .use('svg-sprite-loader')
  87. .loader('svg-sprite-loader')
  88. .options({
  89. symbolId: 'icon-[name]'
  90. })
  91. .end()
  92. config
  93. .when(process.env.NODE_ENV !== 'development',
  94. config => {
  95. config
  96. .plugin('ScriptExtHtmlWebpackPlugin')
  97. .after('html')
  98. .use('script-ext-html-webpack-plugin', [{
  99. inline: /runtime\..*\.js$/
  100. }])
  101. .end()
  102. config
  103. .optimization.splitChunks({
  104. chunks: 'all',
  105. cacheGroups: {
  106. libs: {
  107. name: 'chunk-libs',
  108. test: /[\\/]node_modules[\\/]/,
  109. priority: 10,
  110. chunks: 'initial'
  111. },
  112. elementUI: {
  113. name: 'chunk-elementUI',
  114. priority: 20,
  115. test: /[\\/]node_modules[\\/]_?element-ui(.*)/
  116. },
  117. commons: {
  118. name: 'chunk-commons',
  119. test: resolve('src/components'),
  120. minChunks: 3,
  121. priority: 5,
  122. reuseExistingChunk: true
  123. }
  124. }
  125. })
  126. config.optimization.runtimeChunk('single')
  127. }
  128. )
  129. }
  130. }