vite.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * vite配置
  3. *
  4. * @Author: DCCloud
  5. * @Date: 2022-05-02 23:44:56
  6. */
  7. import { resolve } from 'path';
  8. import vue from '@vitejs/plugin-vue';
  9. import vueJsx from '@vitejs/plugin-vue-jsx';
  10. import customVariables from '/@/theme/custom-variables.js';
  11. const pathResolve = (dir) => {
  12. return resolve(__dirname, '.', dir);
  13. };
  14. export default {
  15. base: process.env.NODE_ENV === 'production' ? '/' : '/',
  16. root: process.cwd(),
  17. resolve: {
  18. alias: [
  19. // 国际化替换
  20. {
  21. find: 'vue-i18n',
  22. replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
  23. },
  24. // 绝对路径重命名:/@/xxxx => src/xxxx
  25. {
  26. find: /\/@\//,
  27. replacement: pathResolve('src') + '/',
  28. },
  29. {
  30. find: /^~/,
  31. replacement: '',
  32. },
  33. ],
  34. },
  35. // 服务端渲染
  36. server: {
  37. host: '0.0.0.0',
  38. port: 8081,
  39. proxy: {
  40. '/api': {
  41. target: 'http://localhost:9000',
  42. // target: 'http://192.168.17.209:2024',
  43. changeOrigin: true,
  44. ws: true,
  45. rewrite: (path) => path.replace(new RegExp(`^/api`), ''),
  46. // only https
  47. // secure: false
  48. },
  49. '/base-api': { // 用于基础
  50. target: 'http://localhost:2025',
  51. // target: 'http://192.168.17.209:2024',
  52. changeOrigin: true,
  53. ws: true,
  54. rewrite: (path) => path.replace(new RegExp(`^/base-api`), ''),
  55. }
  56. },
  57. open: true, // 项目启动后,自动打开
  58. },
  59. plugins: [vue(), vueJsx({})],
  60. optimizeDeps: {
  61. include: ['ant-design-vue/es/locale/zh_CN', 'dayjs/locale/zh-cn', 'ant-design-vue/es/locale/en_US'],
  62. exclude: ['vue-demi'],
  63. },
  64. build: {
  65. // 清除console和debugger
  66. terserOptions: {
  67. compress: {
  68. drop_console: true,
  69. drop_debugger: true,
  70. },
  71. },
  72. rollupOptions: {
  73. output: {
  74. //配置这个是让不同类型文件放在不同文件夹,不会显得太乱
  75. chunkFileNames: 'js/[name]-[hash].js',
  76. entryFileNames: 'js/[name]-[hash].js',
  77. assetFileNames: '[ext]/[name]-[hash].[ext]',
  78. manualChunks(id) {
  79. //静态资源分拆打包
  80. if (id.includes('node_modules')) {
  81. return id.toString().split('node_modules/')[1].split('/')[0].toString();
  82. }
  83. },
  84. },
  85. // external: [
  86. // '@antv/x6',
  87. // '@antv/x6-plugin-stencil',
  88. // '@antv/x6-plugin-keyboard',
  89. // '@antv/x6-plugin-scroller',
  90. // '@antv/x6-plugin-selection',
  91. // '@antv/x6-plugin-history',
  92. // '@antv/x6-plugin-clipboard',
  93. // '@antv/x6-plugin-minimap',
  94. // '@antv/x6-plugin-snapline',
  95. // '@antv/x6-plugin-export'
  96. // ],
  97. },
  98. target: 'modules',
  99. outDir: 'dist', // 指定输出路径
  100. assetsDir: 'assets', // 指定生成静态文件目录
  101. assetsInlineLimit: '4096', // 小于此阈值的导入或引用资源将内联为 base64 编码
  102. chunkSizeWarningLimit: 500, // chunk 大小警告的限制
  103. minify: 'terser', // 混淆器,terser构建后文件体积更小
  104. emptyOutDir: true, //打包前先清空原有打包文件
  105. },
  106. css: {
  107. preprocessorOptions: {
  108. less: {
  109. modifyVars: customVariables,
  110. javascriptEnabled: true,
  111. },
  112. },
  113. },
  114. define: {
  115. __INTLIFY_PROD_DEVTOOLS__: false,
  116. 'process.env': process.env,
  117. },
  118. };