diff --git a/.dumi/theme/layouts/GlobalLayout.tsx b/.dumi/theme/layouts/GlobalLayout.tsx
index 5d8373a65c..2958fd1b83 100644
--- a/.dumi/theme/layouts/GlobalLayout.tsx
+++ b/.dumi/theme/layouts/GlobalLayout.tsx
@@ -3,12 +3,12 @@ import {
legacyNotSelectorLinter,
logicalPropertiesLinter,
parentSelectorLinter,
- StyleProvider,
} from '@ant-design/cssinjs';
import { App, theme as antdTheme } from 'antd';
import type { DirectionType } from 'antd/es/config-provider';
import { createSearchParams, useOutlet, useSearchParams } from 'dumi';
import React, { useCallback, useEffect, useMemo } from 'react';
+import { StyleProvider as AntdStyleProvider } from 'antd-style';
import useLayoutState from '../../hooks/useLayoutState';
import SiteThemeProvider from '../SiteThemeProvider';
import useLocation from '../../hooks/useLocation';
@@ -108,7 +108,7 @@ const GlobalLayout: React.FC = () => {
);
return (
-
@@ -132,7 +132,7 @@ const GlobalLayout: React.FC = () => {
-
+
);
};
diff --git a/.dumi/theme/plugin.ts b/.dumi/theme/plugin.ts
index 952a23df96..80fecef646 100644
--- a/.dumi/theme/plugin.ts
+++ b/.dumi/theme/plugin.ts
@@ -2,9 +2,16 @@ import { extractStyle } from '@ant-design/cssinjs';
import type { IApi, IRoute } from 'dumi';
import ReactTechStack from 'dumi/dist/techStacks/react';
import fs from 'fs';
+import path from 'path';
+import chalk from 'chalk';
import sylvanas from 'sylvanas';
+import { extractStaticStyle } from 'antd-style';
+import { createHash } from 'crypto';
import localPackage from '../../package.json';
+export const getHash = (str: string, length = 8) =>
+ createHash('md5').update(str).digest('hex').slice(0, length);
+
/**
* extends dumi internal tech stack, for customize previewer props
*/
@@ -45,6 +52,24 @@ const resolve = (path: string): string => require.resolve(path);
const RoutesPlugin = (api: IApi) => {
const ssrCssFileName = `ssr-${Date.now()}.css`;
+ const writeCSSFile = (key: string, hashKey: string, cssString: string) => {
+ const fileName = `emotion-${key}.${getHash(hashKey)}.css`;
+
+ const filePath = path.join(api.paths.absOutputPath, fileName);
+
+ if (!fs.existsSync(filePath)) {
+ api.logger.event(chalk.grey(`write to: ${filePath}`));
+ fs.writeFileSync(filePath, cssString, 'utf8');
+ }
+
+ return fileName;
+ };
+
+ const addLinkStyle = (html: string, cssFile: string) => {
+ const prefix = api.userConfig.publicPath || api.config.publicPath;
+ return html.replace('', ``);
+ };
+
api.registerTechStack(() => new AntdReactTechStack());
api.modifyRoutes((routes) => {
@@ -81,18 +106,36 @@ const RoutesPlugin = (api: IApi) => {
// FIXME: workaround to make emotion support react 18 pipeableStream
// ref: https://github.com/emotion-js/emotion/issues/2800#issuecomment-1221296308
.map((file) => {
- let styles = '';
-
- // extract all emotion style tags from body
- file.content = file.content.replace(/