vue.config.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const { defineConfig } = require('@vue/cli-service')
  2. function uploadProxyTarget() {
  3. const base = (process.env.VUE_APP_API_BASEURL || '').replace(/\/+$/, '')
  4. return base.replace(/\/adminapi$/i, '') || base
  5. }
  6. module.exports = defineConfig({
  7. //设置为空打包后不分更目录还是多级目录
  8. publicPath:'',
  9. //build编译后存放静态文件的目录
  10. //assetsDir: "static",
  11. // build编译后不生成资源MAP文件
  12. productionSourceMap: false,
  13. //开发服务,build后的生产模式还需nginx代理
  14. devServer: {
  15. allowedHosts: 'all',
  16. open: false, //运行后自动打开浏览器
  17. port: process.env.VUE_APP_PORT, //挂载端口
  18. proxy: {
  19. '/adminapi': {
  20. target: process.env.VUE_APP_API_BASEURL,
  21. ws: true,
  22. pathRewrite: {
  23. '^/adminapi': '/'
  24. }
  25. },
  26. '/upload': {
  27. target: uploadProxyTarget(),
  28. ws: true,
  29. changeOrigin: true
  30. }
  31. }
  32. },
  33. lintOnSave: false,
  34. chainWebpack: config => {
  35. // 移除 prefetch 插件
  36. config.plugins.delete('preload');
  37. config.plugins.delete('prefetch');
  38. config.resolve.alias.set('vue-i18n', 'vue-i18n/dist/vue-i18n.cjs.js');
  39. },
  40. configureWebpack: {
  41. //性能提示
  42. performance: {
  43. hints: false
  44. },
  45. optimization: {
  46. splitChunks: {
  47. chunks: "all",
  48. automaticNameDelimiter: '~',
  49. name: "scuiChunks",
  50. cacheGroups: {
  51. //第三方库抽离
  52. vendor: {
  53. name: "modules",
  54. test: /[\\/]node_modules[\\/]/,
  55. priority: -10
  56. },
  57. elicons: {
  58. name: "elicons",
  59. test: /[\\/]node_modules[\\/]@element-plus[\\/]icons-vue[\\/]/
  60. },
  61. tinymce: {
  62. name: "tinymce",
  63. test: /[\\/]node_modules[\\/]tinymce[\\/]/
  64. },
  65. echarts: {
  66. name: "echarts",
  67. test: /[\\/]node_modules[\\/]echarts[\\/]/
  68. },
  69. xgplayer: {
  70. name: "xgplayer",
  71. test: /[\\/]node_modules[\\/]xgplayer.*[\\/]/
  72. },
  73. codemirror: {
  74. name: "codemirror",
  75. test: /[\\/]node_modules[\\/]codemirror[\\/]/
  76. }
  77. }
  78. }
  79. }
  80. }
  81. })