vue.config.js 4.7 KB

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