@jsxtools/rollup-plugin-copy is a rollup plugin for copying files during the build process.
npm install @jsxtools/rollup-plugin-copyimport { rollupPluginCopy } from "@jsxtools/rollup-plugin-copy";
export default {
input: "src/index.js",
output: {
file: "dist/bundle.js",
format: "es",
},
plugins: [
rollupPluginCopy({
rootDir: "src",
distDir: "dist",
include: ["src/**/*.css", "src/**/*.png", "src/**/*.svg"],
exclude: ["src/**/*.test.*"],
}),
],
};- Copies files from source to destination with glob pattern support.
- Only copies files that have changed using modification time and SHA-256 hash comparison.
- Maintains a cache to avoid unnecessary file operations.
- Handles file additions, changes, and deletions during development.
- Uses Copy-on-Write (CoW) optimization when available (APFS, Btrfs, XFS).
- Integrates with Rollup's asset system.
cacheFile- Cache file for tracking changes (default:cpconfig.cpbuildinfo).include- Glob patterns for files to include (string or array).exclude- Glob patterns for files to exclude (string or array).distDir- Destination directory to copy files to (default:dist).workDir- Current working directory (default: current process directory).rootDir- Source directory to copy files from (default:src)
rollupPluginCopy({
rootDir: "src",
distDir: "dist",
include: ["src/**/*.css", "src/**/*.png", "src/**/*.jpg", "src/**/*.svg"],
});rollupPluginCopy({
rootDir: "assets",
distDir: "public",
include: ["assets/**/*"],
exclude: ["assets/**/*.test.*", "assets/**/.*"],
});The plugin maintains a cache file (default: cpconfig.cpbuildinfo) that tracks file modification times and SHA-256 hashes. This enables:
- Only changed files are copied (based on mtime comparison)
- Content verification using SHA-256 hashes when mtime differs
- Detection of removed files for cleanup
- Minimal file system operations during development
- Incremental builds with accurate change detection
The plugin exports both the main plugin and a separate API:
rollupPluginCopy()- The main Rollup pluginCopyAPI- Available via@jsxtools/rollup-plugin-copy/api
import { CopyAPI } from "@jsxtools/rollup-plugin-copy/api";
const copyApi = new CopyAPI();
copyApi.init({
rootDir: "src",
distDir: "dist",
include: ["src/**/*.css"],
});rollup^4.6.0
MIT-0