-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: antd first-screen style loading
- Loading branch information
1 parent
35578ce
commit 0cd1837
Showing
3 changed files
with
77 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createHash } from 'crypto'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { extractStyle } from '@ant-design/cssinjs'; | ||
import type Entity from '@ant-design/cssinjs/lib/Cache'; | ||
|
||
export type DoExtraStyleOptions = { | ||
cache: Entity; | ||
dir?: string; | ||
baseFileName?: string; | ||
}; | ||
export function doExtraStyle({ cache, dir = 'antd-output', baseFileName = 'antd.min' }: DoExtraStyleOptions) { | ||
const baseDir = path.resolve(__dirname, '../../static/css'); | ||
|
||
const outputCssPath = path.join(baseDir, dir); | ||
|
||
if (!fs.existsSync(outputCssPath)) { | ||
fs.mkdirSync(outputCssPath, { recursive: true }); | ||
} | ||
|
||
const css = extractStyle(cache, true); | ||
if (!css) return ''; | ||
|
||
const md5 = createHash('md5'); | ||
const hash = md5.update(css).digest('hex'); | ||
const fileName = `${baseFileName}.${hash.substring(0, 8)}.css`; | ||
const fullpath = path.join(outputCssPath, fileName); | ||
|
||
const res = `_next/static/css/${dir}/${fileName}`; | ||
|
||
if (fs.existsSync(fullpath)) return res; | ||
|
||
fs.writeFileSync(fullpath, css); | ||
|
||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.