rollup-plugin-globlin
raw JSON → 0.1.4 verified Mon Apr 27 auth: no javascript
Rollup plugin (v0.1.4, latest stable) that provides file watching, copy, transform, repath, and rename capabilities using glob patterns. Differentiates from alternatives like rollup-plugin-copy by offering inline transformation via object or function, clean destination option, and no unnecessary dependencies. Ship TypeScript types. Low release cadence (initial release Aug 2024, no updates since). Primarily used for static asset copying with optional content modification in Rollup builds.
Common errors
error TypeError: globs is not a function ↓
cause Using CommonJS require to import an ESM-only package.
fix
Use import (ESM) instead: import globs from 'rollup-plugin-globlin'
error Error: transform must return a string or object ↓
cause transform callback returns undefined or non-string/object.
fix
Ensure transform returns a string or an object with content property (string).
error Error: Cannot find module 'rollup-plugin-globlin' ↓
cause Package not installed or version does not exist.
fix
Run: pnpm add rollup-plugin-globlin --save-dev
Warnings
breaking v0.1.0 to v0.1.1: function signature for transform callback may change ↓
fix Upgrade to v0.1.1 and adapt transform callback to accept an object with { content, file, dest } properties.
deprecated transform object key 'dest' is deprecated in favor of returning object with 'dest' property ↓
fix Always return { content, file, dest } from transform function or object; dest key in transform config object is ignored.
gotcha transform function must return an object with 'content' as string or a string. Returning a Buffer causes runtime error. ↓
fix Ensure content is a string, e.g., content.toString() if needed.
gotcha if transform returns a string without slash, it renames the file; with slash, it repaths relative to dest. Misunderstanding leads to unexpected output. ↓
fix Review transform documentation: string without slash = rename, string with slash = repath from dest.
gotcha clean: true removes the dest directory before copying; if dest is a parent directory of project files, data loss may occur. ↓
fix Use clean: true with caution; avoid setting dest to root or important project directories.
Install
npm install rollup-plugin-globlin yarn add rollup-plugin-globlin pnpm add rollup-plugin-globlin Imports
- default wrong
const globs = require('rollup-plugin-globlin')correctimport globs from 'rollup-plugin-globlin' - type GlobsOptions wrong
import { GlobsOptions } from 'rollup-plugin-globlin'correctimport type { GlobsOptions } from 'rollup-plugin-globlin' - default (TypeScript) wrong
import * as globs from 'rollup-plugin-globlin'correctimport globs from 'rollup-plugin-globlin'
Quickstart
import globs from 'rollup-plugin-globlin';
import { defineConfig } from 'rollup';
export default defineConfig({
input: 'src/index.js',
output: {
dir: 'dist',
format: 'cjs',
},
plugins: [
globs({
globs: ['assets/**/*.svg'],
dest: 'dist/assets',
clean: true,
transform: {
'**/*.svg': ({ content }) => ({
content: content.toString().toUpperCase(),
file: '[name].SVG',
}),
},
}),
],
});