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:
co-authored by
Claude Opus 4.6
parent
c0a866d027
commit
990aeb03f3
@@ -47,6 +47,31 @@ pipeline, optimizes it, and adds a content hash to the filename for cache
|
||||
busting. Keeping these files outside `static/` ensures they're only included
|
||||
once in your build output.
|
||||
|
||||
## Multiple static directories
|
||||
|
||||
You can serve files from more than one directory by passing an array to the
|
||||
`staticDir` option. When the same filename exists in multiple directories, the
|
||||
first directory in the array takes precedence.
|
||||
|
||||
```ts vite.config.ts
|
||||
import { defineConfig } from "vite";
|
||||
import { fresh } from "@fresh/plugin-vite";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
fresh({
|
||||
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.
|
||||
|
||||
> [info]: If you're using the [Builder](/docs/advanced/builder) API instead of
|
||||
> Vite, the same `staticDir` option accepts a string or an array of strings.
|
||||
|
||||
## Caching headers
|
||||
|
||||
By default, Fresh adds caching headers for the `src` and `srcset` attributes on
|
||||
|
||||
Reference in New Issue
Block a user