vite.config.js 4.1 KB

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