{"id":22028,"library":"rollup-plugin-flatten-dir","title":"rollup-plugin-flatten-dir","description":"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.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/promplate/rollup-plugin-flatten-dir","tags":["javascript","rollup","vite","plugin","flatten","directory","typescript"],"install":[{"cmd":"npm install rollup-plugin-flatten-dir","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-flatten-dir","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-flatten-dir","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required; the plugin is designed for Rollup and Vite.","package":"rollup","optional":true}],"imports":[{"note":"ESM-only; the package ships TypeScript types and does not provide a CommonJS export.","wrong":"const flattenDirPlugin = require('rollup-plugin-flatten-dir')","symbol":"default","correct":"import flattenDirPlugin from 'rollup-plugin-flatten-dir'"},{"note":"The default export is a function, not a named export. Named import will result in undefined.","wrong":"import { flattenDirPlugin } from 'rollup-plugin-flatten-dir'","symbol":"default","correct":"import flattenDirPlugin from 'rollup-plugin-flatten-dir'"},{"note":"Namespace import gives { default: ... }; direct default import is preferred.","wrong":"import * as pkg from 'rollup-plugin-flatten-dir'","symbol":"default","correct":"import pkg from 'rollup-plugin-flatten-dir'"}],"quickstart":{"code":"// rollup.config.js\nimport flattenDirPlugin from 'rollup-plugin-flatten-dir'\n\nexport default {\n  input: 'src/index.js',\n  output: { file: 'dist/bundle.js', format: 'esm' },\n  plugins: [flattenDirPlugin({\n    include: ['**/*.json'],\n    exclude: ['**/node_modules/**'],\n    resolve: 'src/data'\n  })]\n}","lang":"typescript","description":"Basic Rollup configuration using flattenDirPlugin to include JSON files from src/data, excluding node_modules."},"warnings":[{"fix":"Add exclude: ['**/node_modules/**'] to plugin options.","message":"The plugin does not automatically exclude node_modules; you must add an exclude pattern or use a separate plugin to avoid bundling entire node_modules.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use include or exclude patterns to limit to text files (e.g., include: ['**/*.json', '**/*.txt']).","message":"If 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always provide an absolute path or a relative path from process.cwd() to avoid unexpected behavior.","message":"The resolve option with a string resolves relative to process.cwd(); using false disables resolution, which may cause confusing absolute paths.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use default import: import flattenDirPlugin from 'rollup-plugin-flatten-dir'","message":"Version 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.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run npm install rollup-plugin-flatten-dir","cause":"Package not installed or not in node_modules.","error":"Error: Could not resolve 'rollup-plugin-flatten-dir' from '...'"},{"fix":"Change import { flattenDirPlugin } from ... to import flattenDirPlugin from ...","cause":"Importing as a named export instead of default.","error":"TypeError: flattenDirPlugin is not a function"},{"fix":"Ensure the directory specified in resolve exists and is accessible.","cause":"The resolve directory does not exist.","error":"Error: ENOENT: no such file or directory, scandir '...'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}