Registry / devops / vite-plugin-replace-files

vite-plugin-replace-files

JSON →
library1.1.4jsnpmunverified

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-files
INSTALL
IMPORT
SIG · VITE-PLUGIN-REPLAC
V
vite-plugin-replace-files
devopsjavascriptv1.1.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import replaceFiles from 'vite-plugin-replace-files'
import { replaceFiles } from 'vite-plugin-replace-files'
Package exports a default function, not a named export. TypeScript users can do 'import replaceFiles from ...' with esModuleInterop or use 'import replaceFiles = require(...)' for CJS.
ReplaceFilesOptions
import type { ReplaceFilesOptions } from 'vite-plugin-replace-files'
import { ReplaceFilesOptions } from 'vite-plugin-replace-files'
Options type is exported as a named type. Use type-only import to avoid bundling runtime code.
ReplacementRule
import type { ReplacementRule } from 'vite-plugin-replace-files'
import { ReplacementRule } from 'vite-plugin-replace-files'
Also exported as a named type for configuring individual file replacements.

Basic setup: replace 'src/env.ts' with 'conf/env.ts' during build.

import { defineConfig } from 'vite'; import path from 'path'; import replaceFiles from 'vite-plugin-replace-files'; export default defineConfig({ plugins: [ replaceFiles([ { file: path.join('src', 'env.ts'), replacement: path.join('conf', 'env.ts'), }, ]), ], });
Debug
Known issues
breakingPlugin order matters: must be placed before other plugins that rely on the replaced files.
fix
Ensure replaceFiles is the first plugin in the plugins array.
affects: >=1.0.0
gotchaPaths are resolved relative to the project root; absolute paths or path.join usage is recommended.
fix
Always use path.join or absolute paths, e.g., path.join(__dirname, 'src', 'env.ts').
affects: >=1.0.0
gotchaReplacement file must exist at build time; no error if missing, just no replacement.
fix
Verify the replacement path exists or add a check before the build.
affects: >=1.0.0
deprecatedVite 3 support is being dropped; check peer dependencies for your Vite version.
fix
Update to Vite 4+ or stay on older plugin version if using Vite 3.
affects: >=1.1.4
Errors
Common errors & fixes
TypeError: replaceFiles is not a function
Named import instead of default import.
fix
Use 'import replaceFiles from 'vite-plugin-replace-files'' instead of destructuring.
Error: Cannot find module 'vite-plugin-replace-files'
Plugin not installed or not in node_modules.
fix
Run 'npm install -D vite-plugin-replace-files'.
[vite] Internal server error: ENOENT: no such file or directory
Replacement file path does not exist.
fix
Check the replacement path; ensure the file exists at build time.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
vite-plugin-replace-files — npm install vite-plugin-replace-files · libregistry