@jcayzac/astro-build-cache
This module provides a simple build cache for artifacts you may be generating during an Astro build.
As with Astro's own build artifacts, the cache is stored under node_modules/.astro
where it can be easily ignored by version control systems and cached by cloud providers.
$ ls -1 node_modules/.astro/
assets
build-cache.development
build-cache.development-shm
build-cache.development-wal
build-cache.production
build-cache.production-shm
build-cache.production-wal
bundle
chunks
content
data-store.json
To clear the cache, simply delete node_modules/.astro/build-cache.*
.
Installation
pnpm add @jcayzac/astro-build-cache
bunx add @jcayzac/astro-build-cache
npx add @jcayzac/astro-build-cache
yarn add @jcayzac/astro-build-cache
deno add npm:@jcayzac/astro-build-cache
Usage
import { Cache } from '@jcayzac/astro-build-cache'
const { cached } = new Cache('name')
const value = cached<Uint8Array>(
{
format: 'png',
options,
fonts,
element: serializeJsx(node),
},
async () =>
new Resvg(
(await satori(node, options)),
{
fitTo: {
mode: 'width',
value: options.width,
},
},
)
.render()
.asPng(),
)
[!TIP]
To avoid any build error when using this module, you should add it to the list of externalized packages:
export default defineConfig({
vite: {
build: {
rollupOptions: {
external: [
'@jcayzac/astro-build-cache',
],
},
}
},
})
Like it? Buy me a coffee!
If you like anything here, consider buying me a coffee using one of the following platforms: