Skip to content

Commit

Permalink
✨ feat: extractStaticStyle 提供 antd 的ids 计数
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Mar 19, 2023
1 parent c572026 commit 47254d3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/functions/extractStaticStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface StyleItem {
tag: string;
}

const antdCache = createCache();
const defaultAntdCache = createCache();

interface ExtractStyleOptions {
/**
Expand All @@ -51,7 +51,8 @@ export const extractStaticStyle = (html: string, options?: ExtractStyleOptions):
const shouldExtreactAntdStyle =
typeof options?.includeAntd !== 'undefined' ? options.includeAntd : true;

const styleText = extractStyle(options?.antdCache ?? antdCache);
const cache = options?.antdCache ?? defaultAntdCache;
const styleText = extractStyle(cache);

const antdCssString = styleText.replace(/<style\s[^>]*>/g, '').replace(/<\/style>/g, '');

Expand All @@ -63,7 +64,7 @@ export const extractStaticStyle = (html: string, options?: ExtractStyleOptions):
dangerouslySetInnerHTML={{ __html: antdCssString }}
/>
),
ids: [],
ids: Array.from(cache.cache.keys()),
key: 'antd',
css: antdCssString,
tag: `<style data-antd-version="${version}">${antdCssString}</style>`,
Expand Down Expand Up @@ -100,4 +101,4 @@ export const extractStaticStyle = (html: string, options?: ExtractStyleOptions):
return styles.filter(Boolean) as StyleItem[];
};

extractStaticStyle.cache = antdCache;
extractStaticStyle.cache = defaultAntdCache;

0 comments on commit 47254d3

Please sign in to comment.