Interesting “use case”!
When I was developing my front end but hadn’t gotten around to build my REST API yet, I also had to use a mock data file with sample API responses to test out my fetches, and had to change the file before building for production.
However, I did some digging and I think there’s actually a solution for our problems, albeit a slightly more complicated one:
https://vitejs.dev/config/#conditional-config
https://vitejs.dev/config/#define
Vite supports conditional configuration based on the mode type, and combined with the define pre processor, we could probably do something like:
config = { …defaultConfig }
if(command === “dev”) {
config.define = {
DATA_FILE: JSON.stringify(“./data.dev.js)
}
} else {
// etc…
}
Haven’t actually tested it out yet, but I think it’ll work!