vite.config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import vue from '@vitejs/plugin-vue';
  2. import {resolve} from 'path';
  3. import {defineConfig, loadEnv, ConfigEnv} from 'vite';
  4. // import vueSetupExtend from 'vite-plugin-vue-setup-extend';
  5. const pathResolve = (dir: string) => {
  6. return resolve(__dirname, '.', dir);
  7. };
  8. const alias: Record<string, string> = {
  9. '/@': pathResolve('./src/'),
  10. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  11. };
  12. const viteConfig = defineConfig((mode: ConfigEnv) => {
  13. const env = loadEnv(mode.mode, process.cwd());
  14. return {
  15. // plugins: [vue(), vueSetupExtend()],
  16. plugins: [vue()],
  17. root: process.cwd(),
  18. resolve: {alias},
  19. base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
  20. optimizeDeps: {
  21. include: ['element-plus/es/locale/lang/zh-cn', 'element-plus/es/locale/lang/en', 'element-plus/es/locale/lang/zh-tw'],
  22. },
  23. server: {
  24. host: '0.0.0.0',
  25. port: env.VITE_PORT as unknown as number,
  26. open: JSON.parse(env.VITE_OPEN),
  27. hmr: true,
  28. /* proxy: {
  29. '/admin': {
  30. target: 'https://www.kuaiyuman.cn/admin/',
  31. changeOrigin: true,
  32. // rewrite: (path) => path.replace(/^\/admin/, '')
  33. }
  34. }*/
  35. },
  36. build: {
  37. outDir: '../admin/src/main/resources/static',
  38. chunkSizeWarningLimit: 1500,
  39. rollupOptions: {
  40. output: {
  41. entryFileNames: `assets/[name].[hash].js`,
  42. chunkFileNames: `assets/[name].[hash].js`,
  43. assetFileNames: `assets/[name].[hash].[ext]`,
  44. compact: true,
  45. manualChunks: {
  46. vue: ['vue', 'vue-router', 'pinia'],
  47. echarts: ['echarts'],
  48. },
  49. },
  50. },
  51. },
  52. css: {preprocessorOptions: {css: {charset: false}}},
  53. define: {
  54. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  55. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  56. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  57. __NEXT_VERSION__: JSON.stringify(process.env.npm_package_version),
  58. __NEXT_NAME__: JSON.stringify(process.env.npm_package_name),
  59. },
  60. };
  61. });
  62. export default viteConfig;