Vite plugin that replaces files during build with other files, useful when simple string replacement is insufficient (e.g., swapping entire configuration or environment files). Current stable version is 1.1.4, released with support for Vite 3 through 8. It ships TypeScript types. Key differentiators: operates at file level rather than string substitution, works with Vite's build pipeline, and is lightweight with no runtime dependencies. Frequent releases to keep peer dependency compatibility with Vite versions.
npm install vite-plugin-replace-filesVerified import paths — ran on the pinned version, not inferred.
Basic setup: replace 'src/env.ts' with 'conf/env.ts' during build.
Ensure replaceFiles is the first plugin in the plugins array.
Always use path.join or absolute paths, e.g., path.join(__dirname, 'src', 'env.ts').
Verify the replacement path exists or add a check before the build.
Update to Vite 4+ or stay on older plugin version if using Vite 3.
Use 'import replaceFiles from 'vite-plugin-replace-files'' instead of destructuring.
Run 'npm install -D vite-plugin-replace-files'.
Check the replacement path; ensure the file exists at build time.
No dependency data recorded yet.