【前端】智能库房综合管理系统前端项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.0 KiB

4 years ago
4 years ago
2 weeks ago
  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: process.env.NODE_ENV === 'development' ? '/' : './',
  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: true
  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. '/denseshelf': {
  41. target: process.env.VUE_APP_BASE_API,
  42. changeOrigin: true,
  43. pathRewrite: {
  44. '^/denseshelf': 'denseshelf'
  45. }
  46. }
  47. }
  48. },
  49. configureWebpack: {
  50. name: name,
  51. resolve: {
  52. alias: {
  53. '@': resolve('src'),
  54. '@crud': resolve('src/components/Crud')
  55. }
  56. },
  57. performance: {
  58. hints: 'warning',
  59. // 入口起点的最大体积
  60. maxEntrypointSize: 50000000,
  61. // 生成文件的最大体积
  62. maxAssetSize: 30000000
  63. }
  64. },
  65. chainWebpack(config) {
  66. config.plugins.delete('preload') // TODO: need test
  67. config.plugins.delete('prefetch') // TODO: need test
  68. // set svg-sprite-loader
  69. config.module
  70. .rule('svg')
  71. .exclude.add(resolve('src/assets/icons'))
  72. .end()
  73. config.module
  74. .rule('icons')
  75. .test(/\.svg$/)
  76. .include.add(resolve('src/assets/icons'))
  77. .end()
  78. .use('svg-sprite-loader')
  79. .loader('svg-sprite-loader')
  80. .options({
  81. symbolId: 'icon-[name]'
  82. })
  83. .end()
  84. // set preserveWhitespace
  85. config.module
  86. .rule('vue')
  87. .use('vue-loader')
  88. .loader('vue-loader')
  89. .tap(options => {
  90. options.compilerOptions.preserveWhitespace = true
  91. return options
  92. })
  93. .end()
  94. config
  95. // https://webpack.js.org/configuration/devtool/#development
  96. .when(process.env.NODE_ENV === 'development',
  97. config => config.devtool('cheap-source-map')
  98. )
  99. config
  100. .when(process.env.NODE_ENV !== 'development',
  101. config => {
  102. config
  103. .plugin('ScriptExtHtmlWebpackPlugin')
  104. .after('html')
  105. .use('script-ext-html-webpack-plugin', [{
  106. // `runtime` must same as runtimeChunk name. default is `runtime`
  107. inline: /runtime\..*\.js$/
  108. }])
  109. .end()
  110. config
  111. .optimization.splitChunks({
  112. chunks: 'all',
  113. cacheGroups: {
  114. libs: {
  115. name: 'chunk-libs',
  116. test: /[\\/]node_modules[\\/]/,
  117. priority: 10,
  118. chunks: 'initial' // only package third parties that are initially dependent
  119. },
  120. elementUI: {
  121. name: 'chunk-elementUI', // split elementUI into a single package
  122. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  123. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  124. },
  125. commons: {
  126. name: 'chunk-commons',
  127. test: resolve('src/components'), // can customize your rules
  128. minChunks: 3, // minimum common number
  129. priority: 5,
  130. reuseExistingChunk: true
  131. }
  132. }
  133. })
  134. config.optimization.runtimeChunk('single')
  135. }
  136. )
  137. },
  138. transpileDependencies: [
  139. 'vue-echarts',
  140. 'resize-detector'
  141. ]
  142. }