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.

89 lines
2.6 KiB

  1. 'use strict'
  2. const path = require('path')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. module.exports = {
  7. // 基础配置 详情看文档
  8. publicPath: './',
  9. outputDir: 'dist',
  10. assetsDir: 'static',
  11. lintOnSave: process.env.NODE_ENV === 'development',
  12. productionSourceMap: false,
  13. devServer: {
  14. port: process.env.VUE_APP_CLI_PORT,
  15. open: true,
  16. overlay: {
  17. warnings: false,
  18. errors: true
  19. },
  20. proxy: {
  21. // 把key的路径代理到target位置
  22. // detail: https://cli.vuejs.org/config/#devserver-proxy
  23. [process.env.VUE_APP_BASE_API]: { // 需要代理的路径 例如 '/api'
  24. target: `${process.env.VUE_APP_BASE_PATH}:${process.env.VUE_APP_SERVER_PORT}/`, // 代理到 目标路径
  25. changeOrigin: true,
  26. pathRewrite: { // 修改路径数据
  27. ['^' + process.env.VUE_APP_BASE_API]: '' // 举例 '^/api:""' 把路径中的/api字符串删除
  28. }
  29. }
  30. }
  31. },
  32. configureWebpack: {
  33. // @路径走src文件夹
  34. resolve: {
  35. alias: {
  36. '@': resolve('src')
  37. }
  38. }
  39. },
  40. chainWebpack(config) {
  41. config
  42. // https://webpack.js.org/configuration/devtool/#development
  43. .when(process.env.NODE_ENV === 'development',
  44. config => config.devtool('cheap-source-map')
  45. )
  46. config
  47. .when(process.env.NODE_ENV !== 'development',
  48. config => {
  49. config.plugin('html')
  50. .tap(args => {
  51. args[0].title = 'GIN-VUE-ADMIN'
  52. return args
  53. })
  54. config
  55. .plugin('ScriptExtHtmlWebpackPlugin')
  56. .after('html')
  57. .use('script-ext-html-webpack-plugin', [{
  58. // `runtime` must same as runtimeChunk name. default is `runtime`
  59. inline: /single\..*\.js$/
  60. }])
  61. .end()
  62. config
  63. .optimization.splitChunks({
  64. chunks: 'all',
  65. cacheGroups: {
  66. libs: {
  67. name: 'chunk-libs',
  68. test: /[\\/]node_modules[\\/]/,
  69. priority: 10,
  70. chunks: 'initial' // only package third parties that are initially dependent
  71. },
  72. commons: {
  73. name: 'chunk-commons',
  74. test: resolve('src/components'), // can customize your rules
  75. minChunks: 3, // minimum common number
  76. priority: 5,
  77. reuseExistingChunk: true
  78. }
  79. }
  80. })
  81. config.optimization.runtimeChunk('single')
  82. }
  83. )
  84. }
  85. }