vite.config.ts 2.7 KB

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