【前端】智能库房综合管理系统前端项目
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.

150 lines
4.1 KiB

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