{"id":22157,"library":"rollup-plugin-path-rewrite","title":"rollup-plugin-path-rewrite","description":"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.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/Grumaks/rollup-plugin-path-rewrite","tags":["javascript","rollup-plugin","rollup","plugin","path","rewrite","replace","output","directory","typescript"],"install":[{"cmd":"npm install rollup-plugin-path-rewrite","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-path-rewrite","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-path-rewrite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: required as the plugin host.","package":"rollup","optional":false}],"imports":[{"note":"Default export only; named import will cause undefined.","wrong":"import { pathRewrite } from 'rollup-plugin-path-rewrite'","symbol":"pathRewrite","correct":"import pathRewrite from 'rollup-plugin-path-rewrite'"},{"note":"CJS usage: the entire module exports the plugin function as default.","wrong":"const { pathRewrite } = require('rollup-plugin-path-rewrite')","symbol":"(none)","correct":"const pathRewrite = require('rollup-plugin-path-rewrite')"},{"note":"TypeScript: type is exported for option configuration.","symbol":"RollupPluginPathRewriteOptions","correct":"import type { RollupPluginPathRewriteOptions } from 'rollup-plugin-path-rewrite'"}],"quickstart":{"code":"// rollup.config.js\nimport pathRewrite from 'rollup-plugin-path-rewrite';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'es',\n    preserveModules: true,\n  },\n  plugins: [\n    pathRewrite({\n      test: /\\.d\\.ts$/i,\n      replaceTo: (path) => `types/${path}`,\n    }),\n  ],\n};","lang":"javascript","description":"Minimal rollup config using pathRewrite to move .d.ts files into a types/ subdirectory while preserving modules."},"warnings":[{"fix":"Ensure your use case is purely path rewriting; for content changes, use rollup-plugin-replace or similar.","message":"Plugin only operates on generated output paths; it does not modify file contents. If you need content transformation, use a different plugin.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For group replacements: `replaceTo: (path) => path.replace(/pattern/, '$1')`","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If paths are not being rewritten, verify that `preserveModules: true` is set in the output config.","message":"The plugin relies on Rollup's output options like `preserveModules` to generate separate files. Without `preserveModules`, there may be fewer paths to rewrite.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"","message":"No known deprecations.","severity":"deprecated","affected_versions":""}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Change `import { pathRewrite }` to `import pathRewrite`","cause":"Using named import instead of default import.","error":"TypeError: pathRewrite is not a function"},{"fix":"Run `npm install rollup --save-dev`","cause":"Rollup is not installed as a dev dependency or peer dependency.","error":"Error: Could not resolve 'rollup-plugin-path-rewrite' (missing peer dep rollup)"},{"fix":"Ensure `preserveModules: true` is set and the `test` regex matches the file extensions you expect.","cause":"The `test` regex does not match any generated output paths, or `preserveModules` is not enabled.","error":"InputError: The plugin does not modify files in place; no output directories matched your filter."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}