rollup-plugin-rename
raw JSON → 1.0.1 verified Mon Apr 27 auth: no javascript
Rollup plugin that renames file paths before they are emitted, rewriting all imports and exports across the bundle to match the new names. Current version is 1.0.1, with a simple API: a map function transforms original file paths to new ones. Unlike other rename plugins, it supports include/exclude patterns and source map generation. Particularly useful when using preserveModules to restructure output directories. No ongoing maintenance activity observed since 2021.
Common errors
error Error: Cannot find module '@betit/rollup-plugin-rename' ↓
cause Import path without @betit/ scope or missing package install.
fix
npm install @betit/rollup-plugin-rename --save-dev && use import rename from '@betit/rollup-plugin-rename';
error TypeError: rename is not a function ↓
cause Wrong import style: { rename } instead of default import.
fix
import rename from '@betit/rollup-plugin-rename';
error The plugin 'rename' is not a function or valid Rollup plugin. ↓
cause Imported module is not the plugin itself, perhaps a re-export wrapper.
fix
Ensure you are importing the default export from '@betit/rollup-plugin-rename'.
Warnings
gotcha The plugin does not apply to entry points; only internal module paths are renamed. Entry output filename remains unchanged. ↓
fix Manually rename entry file in output options or use additional plugin.
gotcha The include option filters which files are eligible for renaming, but code that imports or exports those files will have import paths rewritten even if the importer is not in include. ↓
fix Ensure the map function handles all possible paths; use include to limit scope.
deprecated Package is published under scoped name @betit/rollup-plugin-rename on npm. Legacy import path without @betit/ is no longer functional. ↓
fix Use import from '@betit/rollup-plugin-rename'; check package.json of your rollup config.
gotcha If you use the map function to change file extensions (e.g., .ts to .js), the plugin does not update the output file extension; it only renames the path string. Use rollup-plugin-rename-extensions for extension changes. ↓
fix Use dedicated extension-rename plugin or handle extension logic in build script.
gotcha The plugin may not work correctly with non-JS loaders (e.g., images, CSS) that output chunks with non-standard import rewriting. ↓
fix Test with simple file types; open an issue for unsupported cases.
Install
npm install rollup-plugin-rename yarn add rollup-plugin-rename pnpm add rollup-plugin-rename Imports
- rename wrong
const rename = require('@betit/rollup-plugin-rename');correctimport rename from '@betit/rollup-plugin-rename'; - IRenameExtensionsOptions wrong
import { IRenameExtensionsOptions } from '@betit/rollup-plugin-rename';correctimport type { IRenameExtensionsOptions } from '@betit/rollup-plugin-rename'; - default (rename) wrong
import { rename } from '@betit/rollup-plugin-rename';correctimport rename from '@betit/rollup-plugin-rename';
Quickstart
import rename from '@betit/rollup-plugin-rename';
import { defineConfig } from 'rollup';
export default defineConfig({
input: 'src/index.ts',
preserveModules: true,
output: {
dir: 'dist',
format: 'es',
},
plugins: [
rename({
include: ['**/*.ts'],
map: (name) => name.replace('src/', 'dist/'),
sourceMap: true,
}),
],
});