Skip to content

Commit 58fd03f

Browse files
committed
feat(@142vip/vitepress): 对依赖进行小版本升级,优化组件导入方式,支持sass高版本编译
1 parent 74170bf commit 58fd03f

10 files changed

Lines changed: 1213 additions & 818 deletions

File tree

packages/vitepress/package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,30 @@
7070
"peerDependencies": {
7171
"@142vip/cdn": "0.0.1-alpha.0",
7272
"@142vip/open-source": "workspace:*",
73-
"element-plus": "2.9.7",
74-
"mermaid": "11.12.0",
73+
"element-plus": "2.13.1",
74+
"mermaid": "11.16.0",
7575
"vitepress": "1.6.4",
76-
"vue": "3.5.22"
76+
"vue": "3.5.40"
7777
},
7878
"dependencies": {
7979
"@142vip/cdn": "0.0.1-alpha.0",
8080
"@142vip/open-source": "workspace:*",
8181
"copy-to-clipboard": "4.0.2",
82-
"element-plus": "2.9.7",
83-
"mermaid": "11.12.0",
82+
"element-plus": "2.13.1",
83+
"mermaid": "11.16.0",
8484
"vitepress": "1.6.4",
85-
"vue": "3.5.22"
85+
"vue": "3.5.40"
8686
},
8787
"devDependencies": {
8888
"mkdist": "2.4.1",
89-
"sass": "1.99.0",
90-
"typedoc": "0.28.12",
89+
"sass": "1.102.0",
90+
"typedoc": "0.28.20",
9191
"typedoc-github-wiki-theme": "2.1.0",
92-
"typedoc-plugin-frontmatter": "1.3.0",
93-
"typedoc-plugin-markdown": "4.9.0",
92+
"typedoc-plugin-frontmatter": "1.3.1",
93+
"typedoc-plugin-markdown": "4.12.0",
9494
"typedoc-plugin-remark": "2.0.1",
95-
"typedoc-vitepress-theme": "1.1.2",
96-
"unplugin-element-plus": "0.11.1",
97-
"vue-sfc-transformer": "0.1.14"
95+
"typedoc-vitepress-theme": "1.1.3",
96+
"unplugin-element-plus": "0.11.2",
97+
"vue-sfc-transformer": "0.2.3"
9898
}
9999
}

packages/vitepress/src/core/mermaid-vite.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/vitepress/src/core/mermaid.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1+
import type { MarkdownOptions, UserConfig } from 'vitepress'
12
import { parseVipMermaidFenceInfo } from './mermaid-theme'
23

3-
interface MarkdownItLike {
4-
renderer: {
5-
rules: {
6-
fence?: (
7-
tokens: Array<{ info: string, content: string }>,
8-
idx: number,
9-
options: unknown,
10-
env: unknown,
11-
self: { renderToken: (tokens: unknown, idx: number, options: unknown) => string },
12-
) => string
13-
}
14-
}
15-
}
4+
/** 与 `markdown.config(md)` 回调参数类型保持一致,避免手写精简接口 */
5+
type MarkdownIt = Parameters<NonNullable<MarkdownOptions['config']>>[0]
166

177
/**
188
* Markdown-it 插件:```mermaid / ```mmd → <VipMermaid>
199
* 需配合主题注册 VipMermaid(defineVipExtendsTheme 已内置)
2010
*/
21-
export function vipMermaidMarkdown(md: MarkdownItLike): void {
11+
export function vipMermaidMarkdown(md: MarkdownIt): void {
2212
const defaultFence = md.renderer.rules.fence?.bind(md.renderer.rules)
2313

2414
md.renderer.rules.fence = (tokens, idx, options, env, self) => {
@@ -39,6 +29,38 @@ export function vipMermaidMarkdown(md: MarkdownItLike): void {
3929
}
4030
}
4131

32+
const MERMAID_OPTIMIZE_DEPS = ['mermaid', '@braintree/sanitize-url', 'copy-to-clipboard'] as const
33+
34+
function mergeOptimizeDepsInclude(
35+
existing: string | string[] | undefined,
36+
): string[] {
37+
const base = existing == null
38+
? []
39+
: Array.isArray(existing)
40+
? [...existing]
41+
: [existing]
42+
43+
for (const dep of MERMAID_OPTIMIZE_DEPS) {
44+
if (!base.includes(dep)) {
45+
base.push(dep)
46+
}
47+
}
48+
return base
49+
}
50+
51+
/** 启用 Mermaid 时合并 Vite 预构建配置,修复 sanitize-url 等依赖的 CJS/ESM 互操作问题 */
52+
export function mergeVipMermaidViteConfig(
53+
vite: UserConfig['vite'] = {},
54+
): NonNullable<UserConfig['vite']> {
55+
return {
56+
...vite,
57+
optimizeDeps: {
58+
...vite.optimizeDeps,
59+
include: mergeOptimizeDepsInclude(vite.optimizeDeps?.include),
60+
},
61+
}
62+
}
63+
4264
export type { VipMermaidOptions, VipMermaidTheme } from './mermaid-theme'
4365
export {
4466
configureVipMermaid,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { UserConfig } from 'vitepress'
2+
3+
type ViteConfig = NonNullable<UserConfig['vite']>
4+
5+
/**
6+
* Sass 现代 API 常量(Vite 5.4+ 支持)。
7+
*
8+
* @see https://sass-lang.com/documentation/breaking-changes/legacy-js-api/
9+
*/
10+
const VIP_SASS_MODERN_API = 'modern' as const
11+
12+
/**
13+
* 合并 Sass 相关 Vite 配置,消除 `legacy-js-api` 弃用告警。
14+
*
15+
* 仅在 `defineVipVitepressConfig(..., { mermaid: true })` 时由框架自动调用;
16+
* 用户已在 `css.preprocessorOptions` 中设置 `api` 时保留原值。
17+
*/
18+
export function mergeVipSassViteConfig(
19+
vite: UserConfig['vite'] = {},
20+
): ViteConfig {
21+
const userScss = vite?.css?.preprocessorOptions?.scss
22+
const userSass = vite?.css?.preprocessorOptions?.sass
23+
24+
return {
25+
...vite,
26+
css: {
27+
...vite?.css,
28+
preprocessorOptions: {
29+
...vite?.css?.preprocessorOptions,
30+
scss: {
31+
...userScss,
32+
api: userScss?.api ?? VIP_SASS_MODERN_API,
33+
},
34+
sass: {
35+
...userSass,
36+
api: userSass?.api ?? VIP_SASS_MODERN_API,
37+
},
38+
},
39+
},
40+
}
41+
}

packages/vitepress/src/core/vip.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ export const vipTeamMembers = [
7878
]
7979

8080
/**
81-
* 基本包结构
81+
* 基本包结构。
82+
* `extends Record<string, unknown>` 便于在 `getPackageJSON<T>()` 等泛型场景下访问扩展字段。
8283
*/
83-
export interface VipPackageJSON {
84+
export interface VipPackageJSON extends Record<string, unknown> {
8485
name: string
8586
version: string
8687
description: string

packages/vitepress/src/core/vitepress.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { MarkdownOptions, UserConfig } from 'vitepress'
22
import type { DefaultTheme } from 'vitepress/types/default-theme'
33
import type { VipMermaidOptions } from './mermaid-theme'
44
import type { NavbarConfig, SidebarConfig } from './types'
5-
import { vipMermaidMarkdown } from './mermaid'
5+
import { mergeVipMermaidViteConfig, vipMermaidMarkdown } from './mermaid'
66
import { configureVipMermaid } from './mermaid-theme'
7-
import { mergeVipMermaidViteConfig } from './mermaid-vite'
7+
import { mergeVipSassViteConfig } from './sass-vite'
88

99
/**
1010
* defineVipVitepressConfig 可选拓展
@@ -53,7 +53,8 @@ export function defineVipVitepressConfig(
5353
return {
5454
...userConfig,
5555
markdown: defineVipMarkdownConfig(userConfig.markdown),
56-
vite: mergeVipMermaidViteConfig(userConfig.vite),
56+
// 增量合并 Vite 配置:Sass 现代 API + Mermaid 依赖预构建(不覆盖用户已显式设置的项)
57+
vite: mergeVipMermaidViteConfig(mergeVipSassViteConfig(userConfig.vite)),
5758
}
5859
}
5960

packages/vitepress/src/env.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference types="vite/client" />
2+
3+
/** 包内 TypeScript 模块声明(构建工具不生成,需在源码侧补充) */
4+
5+
declare module '*.vue' {
6+
import type { DefineComponent } from 'vue'
7+
8+
const component: DefineComponent<object, object, unknown>
9+
export default component
10+
}
11+
12+
declare module '@142vip/cdn/media/svg/*.svg' {
13+
const src: string
14+
export default src
15+
}

packages/vitepress/src/theme/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ export default function defineVipExtendsTheme(theme?: Theme) {
4343
})
4444
},
4545
enhanceApp: ({ app }: EnhanceAppContext) => {
46-
// 按需引入
47-
app.component(ElBacktop)
48-
app.component(ElImage)
49-
app.component(ElTable)
50-
app.component(ElTableColumn)
51-
app.component(ElTag)
46+
// element-plus 2.13+ 的 component() 重载需显式传入组件名
47+
app.component('ElBacktop', ElBacktop)
48+
app.component('ElImage', ElImage)
49+
app.component('ElTable', ElTable)
50+
app.component('ElTableColumn', ElTableColumn)
51+
app.component('ElTag', ElTag)
5252
// Mermaid 组件(配合 defineVipVitepressConfig(..., { mermaid: true }))
5353
app.component('VipMermaid', VipMermaid)
5454
},

packages/vitepress/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
22
"extends": "../../tsconfig.package.json",
3+
"compilerOptions": {
4+
// typedoc 子路径导出在严格模式下需显式 paths,否则 typecheck 报找不到模块
5+
"paths": {
6+
"typedoc": [
7+
"./node_modules/typedoc/dist/types/index.d.ts"
8+
]
9+
}
10+
},
311
"include": [
412
"src/**/*"
513
],

0 commit comments

Comments
 (0)