Registry / devops / rollup-plugin-rename-files

rollup-plugin-rename-files

JSON →
library2.0.0jsnpmunverified

A Rollup plugin that renames output files, primarily used to fix extensions like .less.js to .css.js when bundling with preserveModules. Current version 2.0.0, based on rollup-plugin-rename-node-modules. Active maintenance. Differentiators: allows arbitrary filename transformations via a function, not limited to node_modules or extensions, unlike alternatives like rollup-plugin-rename-extensions or rollup-plugin-rename.

npm install rollup-plugin-rename-files
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-RENA
R
rollup-plugin-rename-files
devopsjavascriptv2.0.0
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.

default
import rename from 'rollup-plugin-rename-files'
const rename = require('rollup-plugin-rename-files')
The plugin uses default export. ESM only; require() will not work in pure ESM context.
RenameOptions
import type { RenameOptions } from 'rollup-plugin-rename-files'
TypeScript type for options object, available since v2.0.0.
default (with type)
import rename from 'rollup-plugin-rename-files'
import { rename } from 'rollup-plugin-rename-files'
The plugin is exported as a default function, not named export.

Shows how to use rollup-plugin-rename-files to rename .less.js output files to .css.js when using preserveModules.

// rollup.config.js import rename from 'rollup-plugin-rename-files'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'cjs', preserveModules: true, }, plugins: [ rename({ includes: '', moduleName: (filename) => filename.replace(/\.less\.js$/g, '.css.js'), }), ], };
Debug
Known issues
breakingv2.0.0 changed default export from a function expecting a string to an object with 'includes' and 'moduleName' options.
fix
Update plugin call to pass an options object: rename({ includes: '', moduleName: (f) => f })
affects: >=2.0.0
deprecatedPassing a string directly to rename() is deprecated since v2.0.0
fix
Use options object with moduleName property instead.
affects: >=2.0.0
gotchaPlugin only affects files output by Rollup; it does not transform source files or handle virtual modules.
fix
Ensure output files are generated with preserveModules or similar setting so filenames can be processed.
affects: *
gotchaIf `includes` is not set (empty string), it applies to all files; specifying a pattern may cause some files to be missed.
fix
Leave includes empty for global rename, or use a glob pattern like '**/*.js'.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: rename is not a function
Incorrect import or CJS require usage in ESM context
fix
Use dynamic import: const rename = (await import('rollup-plugin-rename-files')).default;
Error: The 'includes' option must be a string.
Passing an array or other type for includes
fix
Set includes to a string (e.g., '') or a glob pattern.
TypeError: moduleName must be a string or function
Passing a non-function non-string value for moduleName
fix
Provide a function like (filename) => filename.replace(...) or a string replacement pattern.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
rolluprequiredPeer dependency required for plugin API
Agent activity
6 hits · last 30 days
node
6
Resources
rollup-plugin-rename-files — npm install rollup-plugin-rename-files · libregistry