Rap 原分销系统代码Web
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

148 satır
4.2KB

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