vite.config.ts 2.0 KB

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