rollup-plugin-content

raw JSON →
0.8.0 verified Fri May 01 auth: no javascript

Rollup/Vite plugin for generating i18n static content and summaries from YAML or JSON files. Version 0.8.0, maintained regularly. Enables SPA blogs with i18n support by converting directory structures into importable summary and page modules. Differentiates from static site generators by integrating directly into the build pipeline, providing summary indexes by category and keywords.

error Error: Could not resolve 'rollup-plugin-content'
cause Package not installed or import path incorrect (e.g., missing 'rollup-plugin-content' in package.json)
fix
Run npm install -D rollup-plugin-content and use correct import: import { content } from 'rollup-plugin-content'.
error TypeError: content is not a function
cause Using default import without braces; package exports a named export 'content' as the plugin.
fix
Use import { content } from 'rollup-plugin-content'.
error Module parse failed: Unexpected token (1:0) - You may need an appropriate loader to handle this file type.
cause Rollup/Vite cannot parse YAML files without a parse function provided to the content plugin.
fix
Install js-yaml and pass parse: yaml.load to content() options.
breaking Default export changed from `content` to `{ content as default }` in v0.4.0. Importing without braces may break.
fix Replace `import content from 'rollup-plugin-content'` with `import { content } from 'rollup-plugin-content'` or upgrade to >=0.4.0.
deprecated The `matches` option is deprecated; use Rollup's `include`/`exclude` patterns via @rollup/pluginutils.
fix Replace `matches` with `include` and `exclude` options (e.g., { include: ['**/*.yml'] })
gotcha Files must follow naming convention: `<name>.<lang>.yml` or `<name>.<lang>.json`. Incorrect naming may result in files not being processed.
fix Use format like `about.en.yml`, not `about_en.yml` or `en.about.yml`.
gotcha Summary imports are generated as side-effect modules; you must import them (e.g., `import '../content/pages.summary'`) even if not used in application code.
fix Add an import statement in your entry file referencing the generated summary module.
npm install rollup-plugin-content
yarn add rollup-plugin-content
pnpm add rollup-plugin-content

Rollup configuration to generate i18n content and summaries from YAML files with languages 'en' and 'uk'.

import yaml from 'js-yaml';
import { content } from 'rollup-plugin-content';

export default {
  input: 'src/app.js',
  output: { format: 'es', dir: 'dist', sourcemap: true },
  plugins: [
    content({
      langs: ['en', 'uk'],
      parse: yaml.load,
      plugins: [
        summary({ fields: ['title', 'createdAt'] })
      ]
    })
  ]
};