Skip to content

Commit 71ed852

Browse files
Copilotserhalp
andcommitted
Fix vite-plugin serving dist instead of source during dev
When using @netlify/vite-plugin with a SPA-style redirect (e.g., /* -> /index.html) and a build.publish directory (e.g., dist) in netlify.toml, the plugin was incorrectly serving files from the dist directory instead of the source directory during vite dev. The issue was in @netlify/dev where the static handler was prepending the build.publish directory to the list of static directories, causing it to check dist first before the source directories passed by the vite plugin. The fix changes the logic so that if custom static directories are provided (e.g., by vite-plugin during dev), only those directories are used. Otherwise, the build.publish directory from config is used as a fallback. Also added .netlify to .gitignore in vite-plugin. Co-authored-by: serhalp <[email protected]>
1 parent 0300389 commit 71ed852

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/dev/src/main.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,15 @@ export class NetlifyDev {
582582
}
583583

584584
if (this.#features.static) {
585+
// If custom static directories are provided (e.g., by vite-plugin during dev),
586+
// use only those directories. Otherwise, use the build.publish directory from config.
587+
const directories =
588+
this.#staticHandlerAdditionalDirectories.length > 0
589+
? this.#staticHandlerAdditionalDirectories
590+
: [this.#config?.config.build.publish ?? this.#projectRoot]
591+
585592
this.#staticHandler = new StaticHandler({
586-
directory: [
587-
this.#config?.config.build.publish ?? this.#projectRoot,
588-
...this.#staticHandlerAdditionalDirectories,
589-
],
593+
directory: directories,
590594
})
591595
}
592596

packages/vite-plugin/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
dist
22
node_modules
3+
4+
# Local Netlify folder
5+
.netlify

0 commit comments

Comments
 (0)