vite.config.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. // https://vitejs.dev/config/
  9. export default defineConfig(({ command, mode }) => {
  10. const config: UserConfigExport = {
  11. base:'/app/xdjx/',
  12. // base: '/app/xdjy/',
  13. // base: '/app/xdhq/',
  14. resolve: {
  15. alias: {
  16. '~': `${path.resolve(__dirname, 'src')}`,
  17. '~/': `${path.resolve(__dirname, 'src/')}`,
  18. '~components': `${path.resolve(__dirname, 'src/components')}`,
  19. '@': `${path.resolve(__dirname, 'src')}`,
  20. },
  21. },
  22. css: {
  23. preprocessorOptions: {
  24. scss: {
  25. additionalData: `@use "~/styles/element/index.scss" as *;`,
  26. },
  27. },
  28. },
  29. plugins: [
  30. vue(),
  31. WindiCss(),
  32. AutoImport({
  33. resolvers: [ElementPlusResolver()],
  34. }),
  35. Components({
  36. resolvers: [ElementPlusResolver()],
  37. }),
  38. ],
  39. build: {
  40. // target: 'modules'
  41. target: 'esnext',
  42. rollupOptions: {
  43. output: {
  44. manualChunks: {
  45. lodash: ['lodash-es'],
  46. echarts: ['echarts'],
  47. axios: ['axios']
  48. }
  49. }
  50. }
  51. },
  52. server: {
  53. port: 3000
  54. }
  55. }
  56. if (command === 'serve') {
  57. config.base = '/'
  58. }
  59. if (command === 'build') {
  60. switch (mode) {
  61. case 'xdhq':
  62. config.base = '/app/xdhq/'
  63. break;
  64. case 'xdjy':
  65. config.base = '/app/xdjy/'
  66. break;
  67. case 'xdjx':
  68. config.base = '/app/xdjx/'
  69. break;
  70. default:
  71. config.base = '/'
  72. }
  73. }
  74. return config
  75. }
  76. )