Registry / devops / rollup-plugin-path-rewrite

rollup-plugin-path-rewrite

JSON →
library1.0.2jsnpmunverified

A Rollup plugin for rewriting output file or directory paths, primarily used with Rollup's preserveModules mode in ES module builds. Version 1.0.2 (latest, stable) supports Rollup versions 1.x through 4.x via peer dependencies and ships TypeScript definitions. Unlike generic file transformers, it focuses on post-build path manipulation, allowing regex-based path matching and string/function-based replacements. Ideal for reorganizing declaration files or assets in module-preserving output.

npm install rollup-plugin-path-rewrite
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-PATH
R
rollup-plugin-path-rewrite
devopsjavascriptv1.0.2
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.

pathRewrite
import pathRewrite from 'rollup-plugin-path-rewrite'
import { pathRewrite } from 'rollup-plugin-path-rewrite'
Default export only; named import will cause undefined.
(none)
const pathRewrite = require('rollup-plugin-path-rewrite')
const { pathRewrite } = require('rollup-plugin-path-rewrite')
CJS usage: the entire module exports the plugin function as default.
RollupPluginPathRewriteOptions
import type { RollupPluginPathRewriteOptions } from 'rollup-plugin-path-rewrite'
TypeScript: type is exported for option configuration.

Minimal rollup config using pathRewrite to move .d.ts files into a types/ subdirectory while preserving modules.

// rollup.config.js import pathRewrite from 'rollup-plugin-path-rewrite'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'es', preserveModules: true, }, plugins: [ pathRewrite({ test: /\.d\.ts$/i, replaceTo: (path) => `types/${path}`, }), ], };
Debug
Known issues
breakingPlugin only operates on generated output paths; it does not modify file contents. If you need content transformation, use a different plugin.
fix
Ensure your use case is purely path rewriting; for content changes, use rollup-plugin-replace or similar.
affects: >=1.0.0
gotchaThe `replaceTo` option can be a string or function. If a string, it does NOT support regex replacement groups like $1. Use a function for regex group replacements.
fix
For group replacements: `replaceTo: (path) => path.replace(/pattern/, '$1')`
affects: >=1.0.0
gotchaThe plugin relies on Rollup's output options like `preserveModules` to generate separate files. Without `preserveModules`, there may be fewer paths to rewrite.
fix
If paths are not being rewritten, verify that `preserveModules: true` is set in the output config.
affects: >=1.0.0
deprecatedNo known deprecations.
Errors
Common errors & fixes
TypeError: pathRewrite is not a function
Using named import instead of default import.
fix
Change `import { pathRewrite }` to `import pathRewrite`
Error: Could not resolve 'rollup-plugin-path-rewrite' (missing peer dep rollup)
Rollup is not installed as a dev dependency or peer dependency.
fix
Run `npm install rollup --save-dev`
InputError: The plugin does not modify files in place; no output directories matched your filter.
The `test` regex does not match any generated output paths, or `preserveModules` is not enabled.
fix
Ensure `preserveModules: true` is set and the `test` regex matches the file extensions you expect.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
rolluprequiredPeer dependency: required as the plugin host.
Agent activity
8 hits · last 30 days
node
8
Resources
rollup-plugin-path-rewrite — npm install rollup-plugin-path-rewrite · libregistry