rollup-plugin-drupal-sdc-generator

raw JSON →
1.1.11 verified Mon Apr 27 auth: no javascript

A Rollup plugin that generates Single Directory Components (SDCs) for embedding JavaScript applications into Drupal modules or themes. Current stable version is 1.1.11, released with moderate maintenance cadence. It automates creation of .component.yml, .twig, and other SDC files from templates, replacing placeholders like [name] with component names. Supports both string and object configuration for template directories. Designed specifically for Drupal integration, differentiating from generic Rollup plugins by handling Drupal's SDC structure. Works with Vite via Rollup options and targets Drupal module/theme bundlers.

error Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'rollup-plugin-drupal-sdc-generator'
cause Using CommonJS require() on an ESM-only package.
fix
Change to import drupalSdcGenerator from 'rollup-plugin-drupal-sdc-generator' and ensure your project is ESM (type: module in package.json or use .mjs extension).
error Error: The plugin 'rollup-plugin-drupal-sdc-generator' is not a function
cause Using named import `{ drupalSdcGenerator }` instead of default import.
fix
Use import drupalSdcGenerator from 'rollup-plugin-drupal-sdc-generator' without curly braces.
error For Vite: [plugin:vite:rollup] The plugin 'rollup-plugin-drupal-sdc-generator' is not a function
cause Plugin placed in Vite's top-level `plugins` instead of inside `build.rollupOptions.plugins`.
fix
Move the plugin inside build.rollupOptions.plugins array in your Vite config.
gotcha Vite users must place the plugin inside `build.rollupOptions.plugins`, not in the top-level `plugins` array.
fix Move plugin instantiation to `build.rollupOptions.plugins` in Vite config.
gotcha Template directory defaults to the plugin's internal templates; if not customized, files may be missing or unwanted.
fix Provide a `directory` option pointing to your own templates.
gotcha Placeholder `[name]` in template filenames and contents is replaced; use `\[name\]` for literal `[name]`.
fix Escape with backslash: `\[name\]` to include literal `[name]`.
gotcha Plugin is ESM-only; `require()` throws Module not found error.
fix Use `import` syntax or dynamic `import()`.
gotcha Only one component can be generated per build unless using object `directory` option.
fix Use object form of `directory` to map multiple component names to their template directories.
npm install rollup-plugin-drupal-sdc-generator
yarn add rollup-plugin-drupal-sdc-generator
pnpm add rollup-plugin-drupal-sdc-generator

Minimal Rollup configuration using the plugin with optional custom template directory.

import drupalSdcGenerator from 'rollup-plugin-drupal-sdc-generator';

export default {
  input: 'src/main.js',
  output: {
    dir: 'dist',
    format: 'iife',
  },
  plugins: [
    drupalSdcGenerator({
      directory: 'templates', // optional: defaults to built-in templates
    }),
  ],
};