Registry / devops / vite-plugin-transform

vite-plugin-transform

JSON →
library2.0.1jsnpmunverified

Vite plugin for transforming resources during build, supporting regex replacement, alias resolution, and custom callback functions. Current stable version is 2.0.1, released occasionally with breaking changes from v1.x. Key differentiators: allows both simple key-value replacement and advanced path resolution using custom delimiters (e.g., %{ }%). Alternatives: @rollup/plugin-replace, vite-plugin-html. Note: v2.x changed default delimiters from #{ }% to %{ }% and alias handling.

npm install vite-plugin-transform
INSTALL
IMPORT
SIG · VITE-PLUGIN-TRANSF
V
vite-plugin-transform
devopsjavascriptv2.0.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

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

default
✓ import transformPlugin from 'vite-plugin-transform'
✗ const transformPlugin = require('vite-plugin-transform')
ESM-only; CommonJS require() will fail in Vite config (ESM context). Default export is the plugin function.
transformPlugin
✓ import transformPlugin from 'vite-plugin-transform'
✗ import { transformPlugin } from 'vite-plugin-transform'
No named export; always use default import.
PluginOptions
✓ import type { PluginOptions } from 'vite-plugin-transform'
TypeScript users: import type for options. Not exported as a value.

Basic setup of vite-plugin-transform with custom delimiters (%{ }%), alias resolution, key-value replacement, and custom callback.

// vite.config.js import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import transformPlugin from 'vite-plugin-transform'; export default defineConfig({ plugins: [ vue(), transformPlugin({ tStart: '%{', tEnd: '}%', alias: { '@': '/src', }, replace: { 'REPLACE_ME': 'Hello Friends!', }, exclude: ['node_modules'], callbackArray: [ str => str.replace(/old/gi, 'new'), ], }), ], resolve: { alias: { '@': '/src', }, }, });
Debug
Known issues
breakingDefault delimiters changed from #{ }% to %{ }% in v2.0.0. Old syntax #{key}% will not work without explicit configuration.
fix
Set tStart: '#{' and tEnd: '}%' in options to restore v1 behavior, or update your template syntax to use %{key}%.
affects: >=2.0.0
gotchaAlias resolution only works in non-node_modules files by default; files in node_modules are excluded unless explicitly included.
fix
Add 'node_modules' to the 'exclude' array (it is already excluded) or set 'exclude: []' to process node_modules.
affects: >=1.0.0
deprecatedThe 'resolve' option in v1.x was deprecated; use 'alias' instead since v2.0.0.
fix
Replace 'resolve' with 'alias' in plugin options.
affects: >=2.0.0
gotchaTransformer functions in 'callbackArray' receive the entire file content (string) and must return the modified content. Not per-line.
fix
Ensure callbacks return the full transformed content, not just a line.
affects: >=1.0.0
gotchaThe 'replace' option performs simple string replacement, not regex. For regex, use 'callbackArray'.
fix
Use a function in callbackArray for regex replacement: str => str.replace(/pattern/g, 'replacement').
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'vite-plugin-transform'
Package not installed or installed as devDependency but not found.
fix
Run 'npm install --save-dev vite-plugin-transform' and ensure you are in the correct directory.
TypeError: transformPlugin is not a function
Importing named export instead of default export.
fix
Use 'import transformPlugin from 'vite-plugin-transform'' (no curly braces).
The 'tStart' option requires a string value
Using array or object instead of string for tStart/tEnd.
fix
Set tStart to a string like '%{' (not an array).
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
viterequiredPeer dependency; plugin requires Vite's plugin API
magic-stringrequiredUsed for string manipulation with source maps
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
2
Resources
vite-plugin-transform — npm install vite-plugin-transform · libregistry