vue.config.js 4.7 KB

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