vite.config.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { sveltekit } from '@sveltejs/kit/vite';
  2. import { defineConfig } from 'vite';
  3. import tailwindcss from '@tailwindcss/vite';
  4. import md from 'rollup-plugin-md-ts';
  5. export default defineConfig({
  6. plugins: [
  7. sveltekit(),
  8. tailwindcss(),
  9. md({
  10. marked: {},
  11. include: ['../mds/**/*.md', './src/pages/guide/**/*.md', '../../packages/**/*.md']
  12. })
  13. ],
  14. server: { hmr: true, host: '0.0.0.0', port: 5555 },
  15. build: {
  16. assetsDir: 'build',
  17. rollupOptions: {
  18. output: {
  19. manualChunks: (id: string) => {
  20. // 将 node_modules 中的包拆分到单独的 build/node_modules.js 文件中
  21. if (id.includes('node_modules')) {
  22. return 'vendor/index';
  23. }
  24. // 将 src/components/menu 中的包拆分到单独的 build/common/menu/index.js 文件中
  25. if (id.includes('site/src/components/menu')) {
  26. return 'common/menu/index';
  27. }
  28. // 将 src/pages/Home.svelte 单独拆分到 build/home/index.js 文件中
  29. if (id.includes('src/pages/Home.svelte')) {
  30. return 'home/index';
  31. }
  32. // 将 src/pages/guide/Guide.svelte 单独拆分到 build/guide/index.js 文件中
  33. if (id.includes('src/pages/guide/Guide.svelte')) {
  34. return 'guide/index';
  35. }
  36. const guide = [
  37. 'QuickStart',
  38. 'Theme',
  39. 'Faq',
  40. 'Color',
  41. 'Color_en',
  42. 'Icon',
  43. 'Internation',
  44. 'Compatibility',
  45. 'Logo',
  46. 'About',
  47. 'Changelog',
  48. 'Future',
  49. 'Shortkey',
  50. 'Contribution',
  51. 'Milestone',
  52. 'Vscode',
  53. 'Generator'
  54. ];
  55. // 循环遍历 guide 文件夹下的所有文件,将其单独拆分到 build/guide/xxx/index.js 文件中
  56. for (const item of guide) {
  57. if (id.includes(`src/pages/guide/${item}.svelte`)) {
  58. return `guide/${item}/index`;
  59. }
  60. }
  61. // 将 src/pages/components/Components.svelte 单独拆分到 build/components/index.js 文件中
  62. if (id.includes('src/pages/components/Components.svelte')) {
  63. return 'components/index';
  64. }
  65. const components = ['Api', 'Component', 'FAQ', 'Guide', 'Version'];
  66. // 循环遍历 components 文件夹下的所有文件,将其单独拆分到 build/components/xxx/index.js 文件中
  67. for (const item of components) {
  68. if (id.includes(`src/pages/components/${item}.svelte`)) {
  69. return `components/${item}/index`;
  70. }
  71. }
  72. // 如果 id 包含 doc/guide/xxx.md 则单独拆分到 build/doc/guide/xxx/index.js 文件中
  73. if (id.includes('doc/guide/')) {
  74. return 'doc/guide/' + id.match(/doc\/guide\/(.*)\.md/)?.[1] + '/index';
  75. }
  76. // 如果 id 包含 doc/components/xxx.md 则单独拆分到 build/doc/components/xxx/index.js 文件中
  77. if (id.includes('doc/components/')) {
  78. return 'doc/components/' + id.match(/doc\/components\/(.*)\.md/)?.[1] + '/index';
  79. }
  80. }
  81. }
  82. }
  83. }
  84. });