vue.config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const name = defaultSettings.title // 网址标题
  8. // const port = 8013 // 端口配置
  9. const port = 1532 // 端口配置
  10. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  11. module.exports = {
  12. // hash 模式下可使用
  13. //publicPath: process.env.NODE_ENV === 'production' ? '/vhyxt/' : '/vhyxt/',
  14. publicPath: './',
  15. outputDir: 'dist',
  16. assetsDir: 'static',
  17. lintOnSave: process.env.NODE_ENV === 'development',
  18. productionSourceMap: false,
  19. devServer: {
  20. port: port,
  21. open: true,
  22. overlay: {
  23. warnings: false,
  24. errors: true
  25. },
  26. proxy: {
  27. '/api': {
  28. target: process.env.VUE_APP_BASE_API,
  29. changeOrigin: true,
  30. pathRewrite: {
  31. '^/api': 'api'
  32. }
  33. },
  34. '/auth': {
  35. target: process.env.VUE_APP_BASE_API,
  36. changeOrigin: true,
  37. pathRewrite: {
  38. '^/auth': 'auth'
  39. }
  40. }
  41. }
  42. },
  43. configureWebpack: {
  44. // provide the app's title in webpack's name field, so that
  45. // it can be accessed in index.html to inject the correct title.
  46. name: name,
  47. resolve: {
  48. alias: {
  49. '@': resolve('src'),
  50. '@crud': resolve('src/components/Crud')
  51. }
  52. }
  53. },
  54. chainWebpack(config) {
  55. config.plugins.delete('preload') // TODO: need test
  56. config.plugins.delete('prefetch') // TODO: need test
  57. // set svg-sprite-loader
  58. config.module
  59. .rule('svg')
  60. .exclude.add(resolve('src/assets/icons'))
  61. .end()
  62. config.module
  63. .rule('icons')
  64. .test(/\.svg$/)
  65. .include.add(resolve('src/assets/icons'))
  66. .end()
  67. .use('svg-sprite-loader')
  68. .loader('svg-sprite-loader')
  69. .options({
  70. symbolId: 'icon-[name]'
  71. })
  72. .end()
  73. // set preserveWhitespace
  74. config.module
  75. .rule('vue')
  76. .use('vue-loader')
  77. .loader('vue-loader')
  78. .tap(options => {
  79. options.compilerOptions.preserveWhitespace = true
  80. return options
  81. })
  82. .end()
  83. config
  84. // https://webpack.js.org/configuration/devtool/#development
  85. .when(process.env.NODE_ENV === 'development',
  86. config => config.devtool('cheap-source-map')
  87. )
  88. config
  89. .when(process.env.NODE_ENV !== 'development',
  90. config => {
  91. config
  92. .plugin('ScriptExtHtmlWebpackPlugin')
  93. .after('html')
  94. .use('script-ext-html-webpack-plugin', [{
  95. // `runtime` must same as runtimeChunk name. default is `runtime`
  96. inline: /runtime\..*\.js$/
  97. }])
  98. .end()
  99. config
  100. .optimization.splitChunks({
  101. chunks: 'all',
  102. cacheGroups: {
  103. libs: {
  104. name: 'chunk-libs',
  105. test: /[\\/]node_modules[\\/]/,
  106. priority: 10,
  107. chunks: 'initial' // only package third parties that are initially dependent
  108. },
  109. elementUI: {
  110. name: 'chunk-elementUI', // split elementUI into a single package
  111. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  112. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  113. },
  114. commons: {
  115. name: 'chunk-commons',
  116. test: resolve('src/components'), // can customize your rules
  117. minChunks: 3, // minimum common number
  118. priority: 5,
  119. reuseExistingChunk: true
  120. }
  121. }
  122. })
  123. config.optimization.runtimeChunk('single')
  124. }
  125. )
  126. },
  127. transpileDependencies: [
  128. 'vue-echarts',
  129. 'resize-detector'
  130. ]
  131. }