소스 검색

[doc]Change for sveltekit

dufu1991 1 년 전
부모
커밋
97ba9f1fb7
5개의 변경된 파일78개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      docs/site/package.json
  2. 2 2
      docs/site/src/app.html
  3. 4 0
      docs/site/src/routes/+layout.ts
  4. 1 1
      docs/site/tailwind.config.ts
  5. 70 1
      docs/site/vite.config.ts

+ 1 - 1
docs/site/package.json

@@ -20,8 +20,8 @@
 		"@sveltejs/adapter-static": "^3.0.6",
 		"@sveltejs/kit": "^2.9.0",
 		"@sveltejs/vite-plugin-svelte": "^5.0.1",
-		"@types/color": "^4.2.0",
 		"@tailwindcss/typography": "^0.5.15",
+		"@types/color": "^4.2.0",
 		"autoprefixer": "^10.4.20",
 		"beautify-qrcode": "^1.0.3",
 		"clipboard": "^2.0.11",

+ 2 - 2
docs/site/src/app.html

@@ -9,8 +9,8 @@
 		<meta name="description" itemprop="description" content="Mobile web component library based on Svelte and Tailwind" />
 		<meta itemprop="image" content="./assets/images/logo.png" />
 		<title>STDF - 移动 web 组件库</title>
-		<link href="favicon.ico" rel="icon" media="(prefers-color-scheme: light)" />
-		<link href="favicon_black.ico" rel="icon" media="(prefers-color-scheme: dark)" />
+		<link href="/favicon.ico" rel="icon" media="(prefers-color-scheme: light)" />
+		<link href="/favicon_black.ico" rel="icon" media="(prefers-color-scheme: dark)" />
 		<link rel="stylesheet" href="/global.css" />
 		%sveltekit.head%
 	</head>

+ 4 - 0
docs/site/src/routes/+layout.ts

@@ -1,3 +1,7 @@
 // 修改 ssr 为 false,使其不再使用服务端渲染,而是使用客户端渲染
 // Change ssr to false to use client-side rendering instead of server-side rendering
 export const ssr = false;
+
+// 开启预渲染
+// Enable prerendering
+export const prerender = true;

+ 1 - 1
docs/site/tailwind.config.ts

@@ -2,7 +2,7 @@ import typography from '@tailwindcss/typography';
 import type { Config } from 'tailwindcss';
 
 export default {
-	content: ['./src/**/*.{html,svelte}', '../../packages/stdf/**/*.svelte'],
+	content: ['./src/**/*.{html,svelte}', '../../packages/stdf/dist/**/*.svelte'],
 	theme: {
 		colors: {
 			primary: {

+ 70 - 1
docs/site/vite.config.ts

@@ -10,5 +10,74 @@ export default defineConfig({
 			include: ['../mds/**/*.md', './src/pages/guide/**/*.md', '../../packages/**/*.md']
 		})
 	],
-	server: { hmr: true, host: '0.0.0.0', port: 5555 }
+	server: { hmr: true, host: '0.0.0.0', port: 5555 },
+	build: {
+		assetsDir: 'build',
+		rollupOptions: {
+			output: {
+				manualChunks: (id: string) => {
+					// 将 node_modules 中的包拆分到单独的 build/node_modules.js 文件中
+					if (id.includes('node_modules')) {
+						return 'vendor/index';
+					}
+					// 将 src/components/menu 中的包拆分到单独的 build/common/menu/index.js 文件中
+					if (id.includes('site/src/components/menu')) {
+						return 'common/menu/index';
+					}
+					// 将 src/pages/Home.svelte 单独拆分到 build/home/index.js 文件中
+					if (id.includes('src/pages/Home.svelte')) {
+						return 'home/index';
+					}
+					// 将 src/pages/guide/Guide.svelte 单独拆分到 build/guide/index.js 文件中
+					if (id.includes('src/pages/guide/Guide.svelte')) {
+						return 'guide/index';
+					}
+					const guide = [
+						'QuickStart',
+						'Theme',
+						'Faq',
+						'Color',
+						'Color_en',
+						'Icon',
+						'Internation',
+						'Compatibility',
+						'Logo',
+						'About',
+						'Changelog',
+						'Future',
+						'Shortkey',
+						'Contribution',
+						'Milestone',
+						'Vscode',
+						'Generator'
+					];
+					// 循环遍历 guide 文件夹下的所有文件,将其单独拆分到 build/guide/xxx/index.js 文件中
+					for (const item of guide) {
+						if (id.includes(`src/pages/guide/${item}.svelte`)) {
+							return `guide/${item}/index`;
+						}
+					}
+					// 将 src/pages/components/Components.svelte 单独拆分到 build/components/index.js 文件中
+					if (id.includes('src/pages/components/Components.svelte')) {
+						return 'components/index';
+					}
+					const components = ['Api', 'Component', 'FAQ', 'Guide', 'Version'];
+					// 循环遍历 components 文件夹下的所有文件,将其单独拆分到 build/components/xxx/index.js 文件中
+					for (const item of components) {
+						if (id.includes(`src/pages/components/${item}.svelte`)) {
+							return `components/${item}/index`;
+						}
+					}
+					// 如果 id 包含 doc/guide/xxx.md 则单独拆分到 build/doc/guide/xxx/index.js 文件中
+					if (id.includes('doc/guide/')) {
+						return 'doc/guide/' + id.match(/doc\/guide\/(.*)\.md/)?.[1] + '/index';
+					}
+					// 如果 id 包含 doc/components/xxx.md 则单独拆分到 build/doc/components/xxx/index.js 文件中
+					if (id.includes('doc/components/')) {
+						return 'doc/components/' + id.match(/doc\/components\/(.*)\.md/)?.[1] + '/index';
+					}
+				}
+			}
+		}
+	}
 });