Last active
January 28, 2025 16:37
-
-
Save cecilemuller/a8ef2715c334dd80286b54a5780fb88d to your computer and use it in GitHub Desktop.
Vite Plugin: emit an asset using `emitFile` and `configureServer`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { PluginOption } from "vite"; | |
export function plugin(): PluginOption { | |
return [ | |
{ | |
apply: "serve", | |
name: "example-serve", | |
configureServer(server) { | |
server.middlewares.use("/subfolder/example.txt", (_req, res) => { | |
res.appendHeader("Content-Type", "text/plain"); | |
res.end("Generated by vite dev"); | |
}); | |
} | |
}, | |
{ | |
apply: "build", | |
name: "example-build", | |
generateBundle() { | |
this.emitFile({ | |
type: "asset", | |
fileName: "subfolder/example.txt", | |
source: "Generated by vite build", | |
}); | |
} | |
} | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment