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
@@ -55,11 +55,13 @@ export type {
|
||||
* ```
|
||||
*/
|
||||
export function fresh(config?: FreshViteConfig): Plugin[] {
|
||||
const rawStaticDir = config?.staticDir ?? "static";
|
||||
const fConfig: ResolvedFreshViteConfig = {
|
||||
serverEntry: config?.serverEntry ?? "main.ts",
|
||||
clientEntry: config?.clientEntry ?? "client.ts",
|
||||
islandsDir: config?.islandsDir ?? "islands",
|
||||
routeDir: config?.routeDir ?? "routes",
|
||||
staticDir: Array.isArray(rawStaticDir) ? rawStaticDir : [rawStaticDir],
|
||||
ignore: config?.ignore ?? [TEST_FILE_PATTERN],
|
||||
islandSpecifiers: new Map(),
|
||||
namer: new UniqueNamer(),
|
||||
@@ -111,7 +113,7 @@ export function fresh(config?: FreshViteConfig): Plugin[] {
|
||||
noDiscovery: true,
|
||||
},
|
||||
|
||||
publicDir: pathWithRoot("static", config.root),
|
||||
publicDir: pathWithRoot(fConfig.staticDir[0], config.root),
|
||||
|
||||
builder: {
|
||||
async buildApp(builder) {
|
||||
@@ -208,6 +210,9 @@ export function fresh(config?: FreshViteConfig): Plugin[] {
|
||||
|
||||
fConfig.islandsDir = pathWithRoot(fConfig.islandsDir, vConfig.root);
|
||||
fConfig.routeDir = pathWithRoot(fConfig.routeDir, vConfig.root);
|
||||
fConfig.staticDir = fConfig.staticDir.map((d) =>
|
||||
pathWithRoot(d, vConfig.root)
|
||||
);
|
||||
|
||||
config?.islandSpecifiers?.map((spec) => {
|
||||
const specName = specToName(spec);
|
||||
@@ -233,7 +238,7 @@ export function fresh(config?: FreshViteConfig): Plugin[] {
|
||||
clientEntryPlugin(fConfig),
|
||||
...clientSnapshot(fConfig),
|
||||
buildIdPlugin(),
|
||||
...devServer(),
|
||||
...devServer(fConfig),
|
||||
prefresh({
|
||||
include: [/\.[cm]?[tj]sx?$/],
|
||||
exclude: [/node_modules/, /[\\/]+deno[\\/]+npm[\\/]+/],
|
||||
|
||||
Reference in New Issue
Block a user