Registry / web-framework / rollup-plugin-flatten-dir

rollup-plugin-flatten-dir

JSON →
library1.0.1jsnpmunverified

Rollup and Vite plugin that flattens a directory's file contents into a `Record<string, string>` object. Version 1.0.1 is the current stable release, with no active development observable. It resolves a directory, reads file contents, filters by include/exclude glob patterns, and generates an ESM module with a default export mapping relative file paths to their raw string contents. Optionally generates TypeScript declaration files. Differentiates from similar plugins by focusing on raw string contents rather than module transforms.

npm install rollup-plugin-flatten-dir
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-FLAT
R
rollup-plugin-flatten-dir
web-frameworkjavascriptv1.0.1
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 flattenDirPlugin from 'rollup-plugin-flatten-dir'
const flattenDirPlugin = require('rollup-plugin-flatten-dir')
ESM-only; the package ships TypeScript types and does not provide a CommonJS export.
default
import flattenDirPlugin from 'rollup-plugin-flatten-dir'
import { flattenDirPlugin } from 'rollup-plugin-flatten-dir'
The default export is a function, not a named export. Named import will result in undefined.
default
import pkg from 'rollup-plugin-flatten-dir'
import * as pkg from 'rollup-plugin-flatten-dir'
Namespace import gives { default: ... }; direct default import is preferred.

Basic Rollup configuration using flattenDirPlugin to include JSON files from src/data, excluding node_modules.

// rollup.config.js import flattenDirPlugin from 'rollup-plugin-flatten-dir' export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'esm' }, plugins: [flattenDirPlugin({ include: ['**/*.json'], exclude: ['**/node_modules/**'], resolve: 'src/data' })] }
Debug
Known issues
gotchaThe plugin does not automatically exclude node_modules; you must add an exclude pattern or use a separate plugin to avoid bundling entire node_modules.
fix
Add exclude: ['**/node_modules/**'] to plugin options.
affects: >=1.0.0
gotchaIf no include pattern is provided, all files (including binary files) are read as UTF-8 text, which may cause runtime errors for non-text files.
fix
Use include or exclude patterns to limit to text files (e.g., include: ['**/*.json', '**/*.txt']).
affects: >=1.0.0
gotchaThe resolve option with a string resolves relative to process.cwd(); using false disables resolution, which may cause confusing absolute paths.
fix
Always provide an absolute path or a relative path from process.cwd() to avoid unexpected behavior.
affects: >=1.0.0
breakingVersion 1.0.0 changed the default export from a named object to a function. Existing code using import { flatten } from 'rollup-plugin-flatten-dir' will break.
fix
Use default import: import flattenDirPlugin from 'rollup-plugin-flatten-dir'
affects: >=1.0.0
Errors
Common errors & fixes
Error: Could not resolve 'rollup-plugin-flatten-dir' from '...'
Package not installed or not in node_modules.
fix
Run npm install rollup-plugin-flatten-dir
TypeError: flattenDirPlugin is not a function
Importing as a named export instead of default.
fix
Change import { flattenDirPlugin } from ... to import flattenDirPlugin from ...
Error: ENOENT: no such file or directory, scandir '...'
The resolve directory does not exist.
fix
Ensure the directory specified in resolve exists and is accessible.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
rollupoptionalPeer dependency required; the plugin is designed for Rollup and Vite.
Agent activity
8 hits · last 30 days
node
6
Resources
rollup-plugin-flatten-dir — npm install rollup-plugin-flatten-dir · libregistry