vite.config.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import vue from '@vitejs/plugin-vue';
  2. import { resolve } from 'path';
  3. import type { UserConfig, ConfigEnv } from 'vite';
  4. import { defineConfig } from 'vite';
  5. import { loadEnv } from './src/utils/viteBuild';
  6. const pathResolve = (dir: string): any => {
  7. return resolve(__dirname, '.', dir);
  8. };
  9. const { VITE_PORT, VITE_OPEN, VITE_PUBLIC_PATH } = loadEnv();
  10. const alias: Record<string, string> = {
  11. '/@': pathResolve('./src/'),
  12. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  13. };
  14. export default defineConfig(({ command }: ConfigEnv): UserConfig => {
  15. console.log("process.env.VITE_OUTPUT_DIR", process.env.VITE_OUTPUT_DIR);
  16. return {
  17. plugins: [vue()],
  18. root: process.cwd(),
  19. resolve: { alias },
  20. base: command === 'build' ? VITE_PUBLIC_PATH : './',
  21. optimizeDeps: {
  22. include: ['element-plus/lib/locale/lang/zh-cn', 'element-plus/lib/locale/lang/en', 'element-plus/lib/locale/lang/zh-tw'],
  23. },
  24. server: {
  25. host: '0.0.0.0',
  26. port: VITE_PORT,
  27. open: VITE_OPEN,
  28. proxy: {
  29. '/gitee': {
  30. target: 'https://gitee.com',
  31. ws: true,
  32. changeOrigin: true,
  33. rewrite: (path) => path.replace(/^\/gitee/, ''),
  34. },
  35. },
  36. },
  37. build: {
  38. outDir: process.env.VITE_OUTPUT_DIR,
  39. sourcemap: false,
  40. chunkSizeWarningLimit: 1500,
  41. rollupOptions: {
  42. output: {
  43. entryFileNames: `assets/[name].${new Date().getTime()}.js`,
  44. chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
  45. assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
  46. compact: true,
  47. manualChunks: {
  48. vue: ['vue', 'vue-router', 'vuex'],
  49. echarts: ['echarts'],
  50. },
  51. },
  52. },
  53. terserOptions: {
  54. compress: {
  55. drop_console: true,
  56. drop_debugger: true,
  57. },
  58. ie8: true,
  59. output: {
  60. comments: true,
  61. },
  62. },
  63. },
  64. css: {
  65. postcss: {
  66. plugins: [
  67. {
  68. postcssPlugin: 'internal:charset-removal',
  69. AtRule: {
  70. charset: (atRule) => {
  71. if (atRule.name === 'charset') {
  72. atRule.remove();
  73. }
  74. },
  75. },
  76. },
  77. ],
  78. },
  79. },
  80. define: {
  81. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  82. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  83. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  84. },
  85. };
  86. });