vite.config.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. proxy: {
  26. '/gitee': {
  27. target: 'https://gitee.com',
  28. ws: true,
  29. changeOrigin: true,
  30. rewrite: (path) => path.replace(/^\/gitee/, ''),
  31. },
  32. },
  33. },
  34. build: {
  35. outDir: 'dist',
  36. sourcemap: false,
  37. chunkSizeWarningLimit: 1500,
  38. rollupOptions: {
  39. output: {
  40. entryFileNames: `assets/[name].${new Date().getTime()}.js`,
  41. chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
  42. assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
  43. compact: true,
  44. manualChunks: {
  45. vue: ['vue', 'vue-router', 'vuex'],
  46. echarts: ['echarts'],
  47. },
  48. },
  49. },
  50. terserOptions: {
  51. compress: {
  52. drop_console: true,
  53. drop_debugger: true,
  54. },
  55. ie8: true,
  56. output: {
  57. comments: true,
  58. },
  59. },
  60. },
  61. css: {
  62. postcss: {
  63. plugins: [
  64. {
  65. postcssPlugin: 'internal:charset-removal',
  66. AtRule: {
  67. charset: (atRule) => {
  68. if (atRule.name === 'charset') {
  69. atRule.remove();
  70. }
  71. },
  72. },
  73. },
  74. ],
  75. },
  76. },
  77. define: {
  78. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  79. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  80. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  81. },
  82. };
  83. });
  84. export default viteConfig;