vue.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. 'use strict'
  2. const path = require('path')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. const name = '重卡换电智能站控系统'
  7. module.exports = {
  8. publicPath: "/",
  9. outputDir: 'dist',
  10. assetsDir: 'static',
  11. lintOnSave: false,
  12. productionSourceMap: false,
  13. devServer: {
  14. host: 'localhost',
  15. port: 8080,
  16. open: true,
  17. overlay: {
  18. warning: false,
  19. error: true,
  20. },
  21. proxy: {
  22. '/api': {
  23. target: `http://test.hlchsw.com`,
  24. // target: `http://172.16.12.146:8080`,
  25. ws: true,
  26. changeOrigin: true,
  27. },
  28. '/ws': {
  29. target: `ws://test.hlchsw.com/ws`,
  30. // target: `ws://172.16.12.146:8080/ws`,
  31. ws: true,
  32. changeOrigin: true,
  33. },
  34. '/video':{
  35. target: `ws://test.hlchsw.com/`,
  36. // target: `ws://172.16.12.146:8080/ws`,
  37. ws: true,
  38. changeOrigin: true,
  39. }
  40. },
  41. },
  42. configureWebpack: {
  43. // provide the app's title in webpack's name field, so that
  44. // it can be accessed in index.html to inject the correct title.
  45. name: name,
  46. resolve: {
  47. alias: {
  48. '@': resolve('src')
  49. }
  50. }
  51. },
  52. chainWebpack(config) {
  53. config.plugin('preload').tap(() => [
  54. {
  55. rel: 'preload',
  56. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  57. include: 'initial'
  58. }
  59. ])
  60. config.plugins.delete('prefetch')
  61. config.module
  62. .rule('svg')
  63. .exclude.add(resolve('src/icons'))
  64. .end()
  65. config.module
  66. .rule('icons')
  67. .test(/\.svg$/)
  68. .include.add(resolve('src/icons'))
  69. .end()
  70. .use('svg-sprite-loader')
  71. .loader('svg-sprite-loader')
  72. .options({
  73. symbolId: 'icon-[name]'
  74. })
  75. .end()
  76. config
  77. .when(process.env.NODE_ENV !== 'development',
  78. config => {
  79. config
  80. .plugin('ScriptExtHtmlWebpackPlugin')
  81. .after('html')
  82. .use('script-ext-html-webpack-plugin', [{
  83. // `runtime` must same as runtimeChunk name. default is `runtime`
  84. inline: /runtime\..*\.js$/
  85. }])
  86. .end()
  87. config
  88. .optimization.splitChunks({
  89. chunks: 'all',
  90. cacheGroups: {
  91. libs: {
  92. name: 'chunk-libs',
  93. test: /[\\/]node_modules[\\/]/,
  94. priority: 10,
  95. chunks: 'initial' // only package third parties that are initially dependent
  96. },
  97. elementUI: {
  98. name: 'chunk-elementUI', // split elementUI into a single package
  99. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  100. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  101. },
  102. commons: {
  103. name: 'chunk-commons',
  104. test: resolve('src/components'), // can customize your rules
  105. minChunks: 3, // minimum common number
  106. priority: 5,
  107. reuseExistingChunk: true
  108. }
  109. }
  110. })
  111. config.optimization.runtimeChunk('single')
  112. }
  113. )
  114. }
  115. }