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-transformVerified import paths — ran on the pinned version, not inferred.
Basic setup of vite-plugin-transform with custom delimiters (%{ }%), alias resolution, key-value replacement, and custom callback.
Set tStart: '#{' and tEnd: '}%' in options to restore v1 behavior, or update your template syntax to use %{key}%.Add 'node_modules' to the 'exclude' array (it is already excluded) or set 'exclude: []' to process node_modules.
Replace 'resolve' with 'alias' in plugin options.
Ensure callbacks return the full transformed content, not just a line.
Use a function in callbackArray for regex replacement: str => str.replace(/pattern/g, 'replacement').
Run 'npm install --save-dev vite-plugin-transform' and ensure you are in the correct directory.
Use 'import transformPlugin from 'vite-plugin-transform'' (no curly braces).
Set tStart to a string like '%{' (not an array).