vite.config.js 3.3 KB

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