rollup-plugin-mv

raw JSON →
0.0.2 verified Mon Apr 27 auth: no javascript

A Rollup plugin to move generated files and directories after the bundle is written. Version 0.0.2 is the current stable release; the plugin is minimal and has no updates yet. It provides a simple API to specify source and destination paths with optional overwrite and once flags. Compared to alternatives like rollup-plugin-copy or rollup-plugin-sh, it focuses exclusively on moving (not copying) and supports both files and directories. Includes TypeScript declarations.

error Error: ENOENT: no such file or directory, rename 'dist/file' -> 'dist/assets/file'
cause Source file does not exist at the time the plugin runs (e.g., output generation order issue).
fix
Ensure the source is generated before the plugin executes, or use a hook like 'writeBundle' (the plugin already uses 'generateBundle'). Check if the file path is correct.
error TypeError: mv is not a function
cause Using a named import (import { mv } from ...) when the package only exports a default function.
fix
Use default import: import mv from 'rollup-plugin-mv'
error Error: src and dest are required
cause Passing an array with an object that lacks 'src' or 'dest' property.
fix
Ensure each move entry has both 'src' and 'dest' strings: { src: '...', dest: '...' }
gotcha The plugin uses synchronous fs.renameSync under the hood, which fails if source and destination are on different filesystems (e.g., across drives on Windows).
fix Use cross-device-aware tools or ensure source and destination are on the same filesystem.
gotcha The 'once' option only works when there are multiple outputs in the Rollup config. It does not prevent multiple moves if the plugin is included multiple times.
fix Use 'once: true' only when generating multiple outputs from a single config. For multiple plugin instances, consider using a flag or manual check.
gotcha If the destination file or directory already exists and overwrite is false, the move silently fails (no error thrown).
fix Explicitly set overwrite: true or manually remove the destination before running Rollup.
npm install rollup-plugin-mv
yarn add rollup-plugin-mv
pnpm add rollup-plugin-mv

Minimal Rollup configuration using rollup-plugin-mv to move files after build.

// rollup.config.js
import mv from 'rollup-plugin-mv';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'cjs',
  },
  plugins: [
    mv([
      { src: 'dist/file.js', dest: 'dist/assets/file.js' },
      { src: 'dist/folder', dest: 'dist/assets/folder', overwrite: true },
    ], {
      overwrite: false,
      once: false,
    }),
  ],
};