A Vercel build runtime for static websites and single-page applications with zero configuration.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Cache preparation functionality for optimizing build performance across deployments with framework-specific caching strategies and Build Output API support.
Prepares cache files for subsequent builds, improving build performance by preserving dependencies and build artifacts.
/**
* Prepares cache files for subsequent builds to improve performance
* @param options - Cache preparation configuration
* @returns Promise resolving to Files object containing cache entries
*/
function prepareCache(options: PrepareCacheOptions): Promise<Files>;
interface PrepareCacheOptions {
/** Downloaded files from the deployment */
files: Files;
/** Entry point file (typically package.json) */
entrypoint: string;
/** Repository root path (required for monorepos) */
repoRootPath: string;
/** Working directory path */
workPath: string;
/** Build configuration */
config: Config;
}Usage Examples:
import { prepareCache } from "@vercel/static-build";
import type { Files, Config, PackageJson, Framework } from "@vercel/build-utils";
// Type definitions
interface Files {
[filePath: string]: File;
}
interface File {
mode: number;
contentType?: string;
toStream: () => NodeJS.ReadableStream;
toStreamAsync?: () => Promise<NodeJS.ReadableStream>;
}
interface Framework {
slug: string;
dependency?: string;
cachePattern?: string | string[];
name: string;
// ... other framework properties
}
// Basic cache preparation
const cacheFiles = await prepareCache({
files: inputFiles,
entrypoint: "package.json",
repoRootPath: "/build/repo",
workPath: "/build/workspace",
config: {
zeroConfig: true
}
});
// Cache preparation with repository root
const cacheFilesMonorepo = await prepareCache({
files: projectFiles,
entrypoint: "packages/frontend/package.json",
repoRootPath: "/build/repo",
workPath: "/build/repo/packages/frontend",
config: {
framework: "nextjs"
}
});
console.log(Object.keys(cacheFiles)); // Array of cached file pathsThe cache preparation follows this priority order (each returns immediately if found):
config.json cache configuration (returns early if found)build.json cache configuration (returns early if found)**/{.shadow-cljs,node_modules}/**For projects using Build Output API v3, cache files are determined by the config.json file:
interface BuildOutputV3Config {
cache?: string[];
}Example v3 cache configuration:
{
"cache": [
"node_modules/**",
".next/cache/**",
".vercel/cache/**"
]
}For projects using Build Output API v1, cache files are specified in build.json:
interface BuildConfig {
cache: string[];
}Example v1 cache configuration:
{
"cache": [
"node_modules/**",
"dist/.cache/**",
".nuxt/**"
]
}Different frameworks have optimized cache patterns for their build artifacts:
Next.js:
// Caches .next/cache for build optimization
cachePattern: ".next/cache/**"Nuxt.js:
// Caches .nuxt directory for module resolution
cachePattern: ".nuxt/**"Gatsby:
// Caches .cache and public directories
cachePattern: [".cache/**", "public/**"]Vue CLI:
// Caches node_modules for dependency resolution
cachePattern: "node_modules/**"When no specific cache configuration is found, default patterns are applied:
const defaultCachePatterns = [
"**/{.shadow-cljs,node_modules}/**"
];Default cache includes:
node_modules/** - JavaScript dependencies.shadow-cljs/** - ClojureScript build cacheThe cache preparation process:
Cache preparation uses the same framework detection as the build function:
/**
* Detects framework from package.json and config
* @param config - Build configuration
* @param pkg - Package.json contents
* @returns Detected framework or undefined
*/
function getFramework(
config: Config | null,
pkg?: PackageJson | null
): Framework | undefined;Framework detection for caching:
config.zeroConfig is true'package.json'package.json from entrypoint directoryconfig.framework for manual overridecachePattern if availableProper caching provides significant performance improvements:
Typical cache hit improvements:
Install with Tessl CLI
npx tessl i tessl/npm-vercel--static-build