vite.config.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import vueJsx from '@vitejs/plugin-vue-jsx'
  4. import path from 'path'
  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 WindiCSS from 'vite-plugin-windicss'
  9. import Pages from 'vite-plugin-pages'
  10. import { viteMockServe } from 'vite-plugin-mock'
  11. import topLevelAwait from "vite-plugin-top-level-await";
  12. // https://vitejs.dev/config/
  13. export default defineConfig(({ command }) => ({
  14. base: command === 'build' ? '/page/xkxt/' : '/',
  15. resolve: {
  16. alias: {
  17. '~': `${path.resolve(__dirname, 'src')}`,
  18. '@': `${path.resolve(__dirname, 'src')}`,
  19. },
  20. },
  21. css: {
  22. preprocessorOptions: {
  23. scss: {
  24. additionalData: `@use "~/styles/element/index.scss" as *;`,
  25. },
  26. },
  27. },
  28. plugins: [
  29. topLevelAwait({
  30. // The export name of top-level await promise for each chunk module
  31. promiseExportName: "__tla",
  32. // The function to generate import names of top-level await promise in each chunk module
  33. promiseImportName: i => `__tla_${i}`
  34. }),
  35. vue(),
  36. vueJsx(),
  37. viteMockServe({
  38. watchFiles: true,
  39. localEnabled: true,
  40. prodEnabled: false,
  41. }),
  42. // Pages({
  43. // // pagesDir: 'src/views',
  44. // exclude: ['**/components/*.vue'],
  45. // extendRoute: (route) => {
  46. // if (route.path === '') {
  47. // return {
  48. // ...route,
  49. // meta: Object.assign(
  50. // {
  51. // breadcrumb: false,
  52. // },
  53. // route?.meta
  54. // ),
  55. // }
  56. // }
  57. // return route
  58. // },
  59. // }),
  60. WindiCSS(),
  61. AutoImport({
  62. resolvers: [
  63. ElementPlusResolver({
  64. importStyle: 'sass',
  65. }),
  66. ],
  67. }),
  68. Components({
  69. resolvers: [
  70. ElementPlusResolver({
  71. importStyle: 'sass',
  72. }),
  73. ],
  74. }),
  75. ],
  76. }))