feat: support multiple staticDir entries (#3759)

## Summary
- `staticDir` now accepts `string | string[]` in both the **Vite
plugin** (`FreshViteConfig`) and the **Builder API** (`BuildOptions`)
- When multiple directories are specified, they are searched in order
and the first match wins
- **Vite plugin**: first dir maps to Vite's native `publicDir`; extra
dirs are served manually in the dev server and walked during production
builds
- **Builder API**: both `MemoryBuildCache` (dev) and `DiskBuildCache`
(prod) iterate over all directories
- Updated tailwind v3 plugin to use `config.root` instead of
`path.dirname(config.staticDir)`
- Docs updated: `static-files.md`, `vite.md`, `builder.md`

Closes #3105

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bartek Iwańczuk
2026-04-09 07:49:32 +00:00
committed by GitHub
co-authored by Claude Opus 4.6
parent c0a866d027
commit 990aeb03f3
13 changed files with 320 additions and 95 deletions
+21 -4
View File
@@ -40,8 +40,10 @@ const builder = new Builder({
// Where to write generated files when doing a production build.
// (default: `<root>/_fresh/`)
outDir?: string;
// Path to static file directory. (Default: `<root>/static/`)
staticDir?: string;
// Path to static file directory, or an array of directories.
// When multiple directories are specified they are searched in order
// and the first match wins. (Default: `<root>/static/`)
staticDir?: string | string[];
// Path to island directory. (Default: `<root>/islands`)
islandDir?: string;
// Path to routes directory. (Default: `<root>/routes`)
@@ -93,8 +95,23 @@ builder.onTransformStaticFile({
});
```
> [info]: Only static files in `static/` or the value you set `staticDir` to
> will be processed. The builder won't process anything else.
> [info]: Only static files in `static/` or the directories you set `staticDir`
> to will be processed. The builder won't process anything else.
### Multiple static directories
You can pass an array to `staticDir` to serve files from multiple directories.
When the same filename exists in more than one directory, the first directory in
the array takes precedence.
```ts dev.ts
const builder = new Builder({
staticDir: ["static", "generated"],
});
```
This is useful when you have a build step that generates assets into a separate
directory and you want to keep them apart from hand-authored static files.
## Testing