vite.config.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import path from 'path'
  2. import Inspect from 'vite-plugin-inspect'
  3. import { defineConfig, loadEnv } from 'vite'
  4. import VueMacros from 'unplugin-vue-macros/vite'
  5. import UnoCSS from 'unocss/vite'
  6. import mkcert from 'vite-plugin-mkcert'
  7. import glob from 'fast-glob'
  8. import vueJsx from '@vitejs/plugin-vue-jsx'
  9. import Components from 'unplugin-vue-components/vite'
  10. import Icons from 'unplugin-icons/vite'
  11. import IconsResolver from 'unplugin-icons/resolver'
  12. import { docPackage, epPackage, getPackageDependencies, projRoot } from '@kankan-components/build-utils'
  13. import { MarkdownTransform } from './.vitepress/plugins/markdown-transform'
  14. import type { Alias } from 'vite'
  15. const alias: Alias[] = [
  16. {
  17. find: '~/',
  18. replacement: `${path.resolve(__dirname, './.vitepress/vitepress')}/`,
  19. },
  20. ]
  21. if (process.env.DOC_ENV !== 'production') {
  22. alias.push(
  23. {
  24. find: /^kankan-components(\/(es|lib))?$/,
  25. replacement: path.resolve(projRoot, 'packages/kankan-components/index.ts'),
  26. },
  27. {
  28. find: /^kankan-components\/(es|lib)\/(.*)$/,
  29. replacement: `${path.resolve(projRoot, 'packages')}/$2`,
  30. }
  31. )
  32. }
  33. export default defineConfig(async ({ mode }) => {
  34. const env = loadEnv(mode, process.cwd(), '')
  35. // const { dependencies: epDeps } = getPackageDependencies(epPackage)
  36. // const { dependencies: docsDeps } = getPackageDependencies(docPackage)
  37. // const optimizeDeps = [...new Set([...epDeps, ...docsDeps])].filter(dep => !dep.startsWith('@types/') && !['@element-plus/metadata', 'element-plus'].includes(dep))
  38. // optimizeDeps.push(
  39. // ...(await glob(['dayjs/plugin/*.js'], {
  40. // cwd: path.resolve(projRoot, 'node_modules'),
  41. // onlyFiles: true,
  42. // }))
  43. // )
  44. return {
  45. server: {
  46. host: true,
  47. https: !!env.HTTPS,
  48. fs: {
  49. allow: [projRoot],
  50. },
  51. proxy: {
  52. '/demoServer': {
  53. target: 'https://test.4dkankan.com',
  54. changeOrigin: true,
  55. rewrite: path => path.replace(/^\/demoServer/, ''),
  56. },
  57. },
  58. },
  59. resolve: {
  60. alias,
  61. },
  62. plugins: [
  63. VueMacros({
  64. setupComponent: false,
  65. setupSFC: false,
  66. plugins: {
  67. vueJsx: vueJsx(),
  68. },
  69. }),
  70. // https://github.com/antfu/unplugin-vue-components
  71. Components({
  72. dirs: ['.vitepress/vitepress/components'],
  73. allowOverrides: true,
  74. // custom resolvers
  75. resolvers: [
  76. // auto import icons
  77. // https://github.com/antfu/unplugin-icons
  78. IconsResolver(),
  79. ],
  80. // allow auto import and register components used in markdown
  81. include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
  82. }),
  83. // https://github.com/antfu/unplugin-icons
  84. Icons({
  85. autoInstall: true,
  86. }),
  87. UnoCSS(),
  88. MarkdownTransform(),
  89. Inspect(),
  90. mkcert(),
  91. ],
  92. // optimizeDeps: {
  93. // include: optimizeDeps,
  94. // },
  95. }
  96. })