Skip to content

Commit

Permalink
🐛 fix: Fix ssr style
Browse files Browse the repository at this point in the history
canisminor1990 committed Nov 24, 2024
1 parent 800e0a1 commit 96bd8cf
Showing 4 changed files with 33 additions and 13 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -38,6 +38,8 @@ dumi-theme-lobehub is a documentation site theme package designed for `Dumi 2`.
- [🤝 Contributing](#-contributing)
- [🔗 Links](#-links)
- [More Products](#more-products)
- [Design Resources](#design-resources)
- [Development Resources](#development-resources)

####

@@ -192,9 +194,22 @@ Contributions of all types are more than welcome, if you are interested in contr

### More Products

- **[🍭 Lobe UI](https://github.com/lobehub/lobe-ui)** - An open-source UI component library for building AIGC web apps.
- **[🤖 Lobe Chat](https://github.com/lobehub/lobe-chat)** - An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application.
- **[🤯 Lobe Theme](https://github.com/lobehub/sd-webui-lobe-theme)** - The modern theme for stable diffusion webui, exquisite interface design, highly customizable UI, and efficiency boosting features.
- **[🤯 Lobe Chat](https://github.com/lobehub/lobe-chat)** - An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application.
- **[🅰️ Lobe Theme](https://github.com/lobehub/sd-webui-lobe-theme)** - The modern theme for stable diffusion webui, exquisite interface design, highly customizable UI, and efficiency boosting features.
- **[🧸 Lobe Vidol](https://github.com/lobehub/lobe-vidol)** - Experience the magic of virtual idol creation with Lobe Vidol, enjoy the elegance of our Exquisite UI Design, dance along using MMD Dance Support, and engage in Smooth Conversations.

### Design Resources

- **[🍭 Lobe UI](https://ui.lobehub.com)** - An open-source UI component library for building AIGC web apps.
- **[🥨 Lobe Icons](https://lobehub.com/icons)** - Popular AI / LLM Model Brand SVG Logo and Icon Collection.
- **[📊 Lobe Charts](https://charts.lobehub.com)** - React modern charts components built on recharts

### Development Resources

- **[🎤 Lobe TTS](https://tts.lobehub.com)** - A high-quality & reliable TTS/STT library for Server and Browser
- **[🌏 Lobe i18n](https://github.com/lobehub/lobe-cli-toolbox/blob/master/packages/lobe-i18n)** - Automation ai tool for the i18n (internationalization) translation process.

[More Resources](https://lobehub.com/resources)

<div align="right">

11 changes: 6 additions & 5 deletions example/.dumirc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { defineConfig } from 'dumi';
import { resolve } from 'node:path';

import { homepage, name } from '../package.json';
import { description, homepage, name } from '../package.json';

const isProduction = process.env.NODE_ENV === 'production';
const isWin = process.platform === 'win32';

const themeConfig = {
@@ -24,10 +25,8 @@ const themeConfig = {
match: ['/components'],
pkg: name,
sourceUrl: `{github}/tree/master/src/{atomId}/index.tsx`,
type: 'doc',
},
description: 'Lobe UI is an open-source UI component library for building chatbot web apps',
footer: 'Made with 🤯 by <a href="https://lobehub.com" target="_blank">LobeHub</a>',
description,
giscus: {
category: 'Q&A',
categoryId: 'DIC_kwDOJloKoM4CXsCu',
@@ -53,11 +52,13 @@ export default defineConfig({
define: {
'process.env': process.env,
},
exportStatic: {},
favicons: ['https://lobehub.com/favicon.ico'],
jsMinifier: 'swc',
locales: [{ id: 'en-US', name: 'English' }],
mfsu: isWin ? undefined : {},
npmClient: 'pnpm',
ssr: false,
ssr: isProduction ? {} : false,
styles: [
`html, body { background: transparent; }
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@
"@commitlint/cli": "^19.6.0",
"@lobehub/lint": "^1.24.4",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.17.6",
"@types/node": "^20.17.7",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitest/coverage-v8": "~1.2.2",
@@ -111,7 +111,7 @@
"remark-cli": "^11.0.0",
"semantic-release": "^21.1.2",
"stylelint": "^15.11.0",
"typescript": "^5.6.3",
"typescript": "^5.7.2",
"vitest": "~1.2.2"
},
"peerDependencies": {
10 changes: 7 additions & 3 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
@@ -6,11 +6,15 @@ import { join } from 'node:path';

import { getHash } from './utils';

/*
* SSR 抽取样式
*/
const SSRPlugin = (api: IApi) => {
api.describe({
key: '@',
key: 'lobe-docs',
});

// 如果没有开启 SSR,则啥也不做
if (!api.userConfig.ssr) return;

api.logger.info('detect ssr config, when building html will extract css.');
@@ -30,7 +34,6 @@ const SSRPlugin = (api: IApi) => {

const addLinkStyle = (html: string, cssFile: string) => {
const prefix = api.userConfig.publicPath || api.config.publicPath;

return html.replace('</head>', `<link rel="stylesheet" href="${prefix + cssFile}"></head>`);
};

@@ -40,8 +43,9 @@ const SSRPlugin = (api: IApi) => {
.filter((f) => !f.path.includes(':'))

.map((file) => {
const antdCache = (global as any).__LOBE_CACHE__;
const antdCache = (global as any).__ANTD_CACHE__;

// 提取 antd-style 样式到独立 css 文件
const styles = extractStaticStyle(file.content, { antdCache });

for (const result of styles) {

0 comments on commit 96bd8cf

Please sign in to comment.