vite-plugin-replace
What it does
Replace a file by a other file.
Example
with the default generated vite projet:
import { defineConfig } from "vite"
import fileReplace from "./index"
export default defineConfig({
base: "./",
plugins: [
fileReplace({
match: path => path === "/src/counter.ts",
}),
],
}
the match function in config is required to declare files you want to replace.
By default the plugins look for a file start with the same name with the ext mock.ts
instead to replace each file.
You can define how you want to define the filename for replacement with to replace function in config.
import { defineConfig } from "vite"
import fileReplace from "./index"
export default defineConfig({
base: "./",
plugins: [
fileReplace({
match: path => path.startWith("/src/services/")
replace: path => path.replace("/src/services/", "/mock/")
}),
],
}