-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fonts to repo instead of downloading on each build
- Loading branch information
1 parent
8ef198f
commit f2905f7
Showing
16 changed files
with
1,027 additions
and
874 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 |
---|---|---|
|
@@ -3,13 +3,7 @@ import { join } from 'path'; | |
import { env } from 'process'; | ||
import { transform as swc, type Options, type Output } from '@swc/core'; | ||
import { generateDtsBundle } from 'dts-bundle-generator'; | ||
import { | ||
build, | ||
context, | ||
type OnLoadResult, | ||
type OutputFile, | ||
type Plugin, | ||
} from 'esbuild'; | ||
import { build, context, type OutputFile, type Plugin } from 'esbuild'; | ||
import sveltePlugin from 'esbuild-svelte'; | ||
import prettier from 'prettier'; | ||
//@ts-expect-error | ||
Check failure on line 9 in build.ts GitHub Actions / lint
|
||
|
@@ -307,14 +301,11 @@ async function buildWebBundle() { | |
outfile: join(WEB_PATH, 'bundle.js'), | ||
bundle: true, | ||
write: false, | ||
loader: { '.woff2': 'file' }, | ||
keepNames: true, | ||
minify: true, | ||
target: ['esnext'], | ||
plugins: [ | ||
sveltePlugin({ preprocess: autoPreprocess() }), | ||
googleFontPlugin, | ||
regexpuPlugin, | ||
], | ||
plugins: [sveltePlugin({ preprocess: autoPreprocess() }), regexpuPlugin], | ||
}); | ||
|
||
for (const file of outputFiles) { | ||
|
@@ -339,12 +330,12 @@ async function serveWeb() { | |
bundle: true, | ||
sourcemap: true, | ||
write: false, | ||
loader: { '.woff2': 'file' }, | ||
plugins: [ | ||
sveltePlugin({ | ||
preprocess: autoPreprocess(), | ||
compilerOptions: { enableSourcemap: true }, | ||
}), | ||
googleFontPlugin, | ||
], | ||
}); | ||
const server = await ctx.serve({ servedir: WEB_PATH }); | ||
|
@@ -375,31 +366,6 @@ const regexpuPlugin: Plugin = { | |
}, | ||
}; | ||
|
||
// Downloads google fonts and injects them as base64 urls into bundle css | ||
const googleFontPlugin: Plugin = { | ||
name: 'google-font-loader', | ||
setup(build) { | ||
build.onResolve({ filter: /^https?:\/\/fonts\./ }, (args) => ({ | ||
path: args.path, | ||
namespace: 'http-url', | ||
})); | ||
build.onLoad( | ||
{ filter: /.*/, namespace: 'http-url' }, | ||
async (args): Promise<OnLoadResult> => { | ||
const res = await fetch(args.path, { | ||
headers: { | ||
// ensures google responds with woff2 fonts | ||
'User-Agent': 'Mozilla/5.0 Firefox/90.0', | ||
}, | ||
}); | ||
const contents = Buffer.from(await res.arrayBuffer()); | ||
const loader = args.path.endsWith('.woff2') ? 'dataurl' : 'css'; | ||
return { contents, loader }; | ||
}, | ||
); | ||
}, | ||
}; | ||
|
||
/** | ||
* swc converts js syntax to support older browsers. ESBuild can kinda do this | ||
* but only for more recent browsers. swc is also far easier to configure than | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.