多媒体信息发布平台
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.

136 lines
3.3 KiB

3 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. 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. }
  41. },
  42. configureWebpack: {
  43. name: name,
  44. resolve: {
  45. alias: {
  46. '@': resolve('src'),
  47. '@crud': resolve('src/components/Crud')
  48. }
  49. }
  50. },
  51. chainWebpack(config) {
  52. config.plugins.delete('preload') // TODO: need test
  53. config.plugins.delete('prefetch') // TODO: need test
  54. // set svg-sprite-loader
  55. config.module
  56. .rule('svg')
  57. .exclude.add(resolve('src/assets/icons'))
  58. .end()
  59. config.module
  60. .rule('icons')
  61. .test(/\.svg$/)
  62. .include.add(resolve('src/assets/icons'))
  63. .end()
  64. .use('svg-sprite-loader')
  65. .loader('svg-sprite-loader')
  66. .options({
  67. symbolId: 'icon-[name]'
  68. })
  69. .end()
  70. // set preserveWhitespace
  71. config.module
  72. .rule('vue')
  73. .use('vue-loader')
  74. .loader('vue-loader')
  75. .tap(options => {
  76. options.compilerOptions.preserveWhitespace = true
  77. return options
  78. })
  79. .end()
  80. config
  81. .when(process.env.NODE_ENV === 'development',
  82. config => config.devtool('cheap-source-map')
  83. )
  84. config
  85. .when(process.env.NODE_ENV !== 'development',
  86. config => {
  87. config
  88. .plugin('ScriptExtHtmlWebpackPlugin')
  89. .after('html')
  90. .use('script-ext-html-webpack-plugin', [{
  91. inline: /runtime\..*\.js$/
  92. }])
  93. .end()
  94. config
  95. .optimization.splitChunks({
  96. chunks: 'all',
  97. cacheGroups: {
  98. libs: {
  99. name: 'chunk-libs',
  100. test: /[\\/]node_modules[\\/]/,
  101. priority: 10,
  102. chunks: 'initial'
  103. },
  104. elementUI: {
  105. name: 'chunk-elementUI',
  106. priority: 20,
  107. test: /[\\/]node_modules[\\/]_?element-ui(.*)/
  108. },
  109. commons: {
  110. name: 'chunk-commons',
  111. test: resolve('src/components'),
  112. minChunks: 3,
  113. priority: 5,
  114. reuseExistingChunk: true
  115. }
  116. }
  117. })
  118. config.optimization.runtimeChunk('single')
  119. }
  120. )
  121. },
  122. transpileDependencies: [
  123. 'vue-echarts',
  124. 'resize-detector'
  125. ]
  126. }