mirror of https://github.com/vuejs/vitepress
feat(build): add `useWebFonts` option (#1531)
parent
09fcc46079
commit
c9f04e0459
@ -0,0 +1,19 @@
|
|||||||
|
import { Plugin } from 'vite'
|
||||||
|
|
||||||
|
const webfontMarkerRE =
|
||||||
|
/\/(?:\*|\/) *webfont-marker-begin *(?:\*\/|\n|\r|\n\r|\r\n)([^]*?)\/(?:\*|\/) *webfont-marker-end *(?:\*\/|\n|\r|\n\r|\r\n|$)/
|
||||||
|
|
||||||
|
export const webFontsPlugin = (enabled = false): Plugin => ({
|
||||||
|
name: 'vitepress:webfonts',
|
||||||
|
enforce: 'pre',
|
||||||
|
|
||||||
|
transform(code, id) {
|
||||||
|
if (/[\\/]fonts\.s?css/.test(id)) {
|
||||||
|
if (enabled) {
|
||||||
|
return code.match(webfontMarkerRE)?.[1]
|
||||||
|
} else {
|
||||||
|
return code.replace(webfontMarkerRE, '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
Loading…
Reference in new issue