阅行客电子档案
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.

159 lines
4.5 KiB

2 years ago
2 years ago
2 years 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. const GenerateAssetPlugin = require('generate-asset-webpack-plugin')
  11. const createServerConfig = compilation => {
  12. const serverConfig = {
  13. BASE_URL: '' // 打包后生成的文件内容,接口地址
  14. }
  15. return JSON.stringify(serverConfig)
  16. }
  17. module.exports = {
  18. // hash 模式下可使用
  19. publicPath: process.env.NODE_ENV === 'development' ? '/' : './',
  20. // publicPath: '/',
  21. outputDir: 'dist',
  22. assetsDir: 'static',
  23. lintOnSave: process.env.NODE_ENV === 'development',
  24. productionSourceMap: false,
  25. devServer: {
  26. port: port,
  27. open: true,
  28. overlay: {
  29. warnings: false,
  30. errors: true
  31. },
  32. proxy: {
  33. '/api': {
  34. target: process.env.VUE_APP_BASE_API,
  35. changeOrigin: true,
  36. pathRewrite: {
  37. '^/api': 'api'
  38. }
  39. },
  40. '/auth': {
  41. target: process.env.VUE_APP_BASE_API,
  42. changeOrigin: true,
  43. pathRewrite: {
  44. '^/auth': 'auth'
  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. plugins: [
  65. new GenerateAssetPlugin({
  66. filename: 'server-config.json',
  67. fn: (compilation, cb) => {
  68. cb(null, createServerConfig(compilation))
  69. },
  70. extraFiles: []
  71. })
  72. ]
  73. },
  74. chainWebpack(config) {
  75. config.plugins.delete('preload') // TODO: need test
  76. config.plugins.delete('prefetch') // TODO: need test
  77. // set svg-sprite-loader
  78. config.module
  79. .rule('svg')
  80. .exclude.add(resolve('src/assets/icons'))
  81. .end()
  82. config.module
  83. .rule('icons')
  84. .test(/\.svg$/)
  85. .include.add(resolve('src/assets/icons'))
  86. .end()
  87. .use('svg-sprite-loader')
  88. .loader('svg-sprite-loader')
  89. .options({
  90. symbolId: 'icon-[name]'
  91. })
  92. .end()
  93. // set preserveWhitespace
  94. config.module
  95. .rule('vue')
  96. .use('vue-loader')
  97. .loader('vue-loader')
  98. .tap(options => {
  99. options.compilerOptions.preserveWhitespace = true
  100. return options
  101. })
  102. .end()
  103. config
  104. // https://webpack.js.org/configuration/devtool/#development
  105. .when(process.env.NODE_ENV === 'development',
  106. config => config.devtool('cheap-source-map')
  107. )
  108. config
  109. .when(process.env.NODE_ENV !== 'development',
  110. config => {
  111. config
  112. .plugin('ScriptExtHtmlWebpackPlugin')
  113. .after('html')
  114. .use('script-ext-html-webpack-plugin', [{
  115. // `runtime` must same as runtimeChunk name. default is `runtime`
  116. inline: /runtime\..*\.js$/
  117. }])
  118. .end()
  119. config
  120. .optimization.splitChunks({
  121. chunks: 'all',
  122. cacheGroups: {
  123. libs: {
  124. name: 'chunk-libs',
  125. test: /[\\/]node_modules[\\/]/,
  126. priority: 10,
  127. chunks: 'initial' // only package third parties that are initially dependent
  128. },
  129. elementUI: {
  130. name: 'chunk-elementUI', // split elementUI into a single package
  131. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  132. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  133. },
  134. commons: {
  135. name: 'chunk-commons',
  136. test: resolve('src/components'), // can customize your rules
  137. minChunks: 3, // minimum common number
  138. priority: 5,
  139. reuseExistingChunk: true
  140. }
  141. }
  142. })
  143. config.optimization.runtimeChunk('single')
  144. }
  145. )
  146. },
  147. transpileDependencies: [
  148. 'vue-echarts',
  149. 'resize-detector'
  150. ]
  151. }