vite.config.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { defineConfig, UserConfigExport } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import path from 'path'
  4. import WindiCss from 'vite-plugin-windicss';
  5. import AutoImport from 'unplugin-auto-import/vite'
  6. import Components from 'unplugin-vue-components/vite'
  7. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  8. import Icons from 'unplugin-icons/vite'
  9. import IconsResolver from 'unplugin-icons/resolver'
  10. import topLevelAwait from "vite-plugin-top-level-await";
  11. // https://vitejs.dev/config/
  12. export default defineConfig(({ command }) => {
  13. const config: UserConfigExport = {
  14. base: '/manage/',
  15. // base: '/app/xdjy/',
  16. // base: '/app/xdhq/',
  17. resolve: {
  18. alias: {
  19. '~': `${path.resolve(__dirname, 'src')}`,
  20. '~/': `${path.resolve(__dirname, 'src/')}`,
  21. '~components': `${path.resolve(__dirname, 'src/components')}`,
  22. '@': `${path.resolve(__dirname, 'src')}`,
  23. },
  24. },
  25. css: {
  26. preprocessorOptions: {
  27. scss: {
  28. additionalData: `@use "~/styles/element/index.scss" as *;`,
  29. },
  30. },
  31. },
  32. plugins: [
  33. topLevelAwait({
  34. // The export name of top-level await promise for each chunk module
  35. promiseExportName: "__tla",
  36. // The function to generate import names of top-level await promise in each chunk module
  37. promiseImportName: i => `__tla_${i}`
  38. }),
  39. vue({
  40. reactivityTransform: true
  41. }),
  42. WindiCss(),
  43. AutoImport({
  44. resolvers: [ElementPlusResolver()],
  45. }),
  46. Components({
  47. resolvers: [ElementPlusResolver(), IconsResolver()],
  48. }),
  49. Icons({
  50. compiler: 'vue3',
  51. autoInstall: true,
  52. }),
  53. ],
  54. build: {
  55. target: 'chrome86',
  56. // target: 'esnext',
  57. rollupOptions: {
  58. output: {
  59. manualChunks: {
  60. lodash: ['lodash-es'],
  61. echarts: ['echarts'],
  62. axios: ['axios']
  63. }
  64. }
  65. }
  66. },
  67. }
  68. if (command === 'serve') {
  69. config.base = "/"
  70. } else {
  71. }
  72. return config
  73. }
  74. )