Font related improvements
This commit is contained in:
@@ -14,6 +14,13 @@ import { parse } from 'smol-toml'
|
||||
// The waiting worker is still activated explicitly by the user in the console.
|
||||
const pwaBuildId = Date.now().toString(36)
|
||||
const serviceWorkerSource = readFileSync(new URL('./pwa/control-sw.js', import.meta.url), 'utf8')
|
||||
const bundledFontLicenses = ['noto-serif-sc', 'zcool-xiaowei', 'lxgw-wenkai'].map(font => ({
|
||||
fileName: `fonts/licenses/${font}-OFL.txt`,
|
||||
source: readFileSync(
|
||||
new URL(`./node_modules/@fontsource/${font}/LICENSE`, import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
}))
|
||||
const i18nResource = parse(
|
||||
readFileSync(new URL('../../resources/i18n.toml', import.meta.url), 'utf8'),
|
||||
) as unknown as {
|
||||
@@ -51,6 +58,16 @@ const manifest = {
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
react(),
|
||||
{
|
||||
name: 'same-origin-woff2-fonts',
|
||||
enforce: 'pre',
|
||||
transform(source, id) {
|
||||
if (!id.includes('/node_modules/@fontsource/') || !id.endsWith('.css')) return
|
||||
return source
|
||||
.replaceAll('font-display: swap', 'font-display: block')
|
||||
.replace(/,\s*url\([^)]*\.woff\) format\(['"]woff['"]\)/g, '')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'control-pwa-assets',
|
||||
transformIndexHtml(html) {
|
||||
@@ -61,6 +78,9 @@ export default defineConfig({
|
||||
.replaceAll('__APP_DESCRIPTION__', defaultMessages['pwa.manifest.description'])
|
||||
},
|
||||
generateBundle() {
|
||||
for (const license of bundledFontLicenses) {
|
||||
this.emitFile({ type: 'asset', ...license })
|
||||
}
|
||||
this.emitFile({
|
||||
type: 'asset',
|
||||
fileName: 'control/sw.js',
|
||||
|
||||
Reference in New Issue
Block a user