{"id":21991,"library":"rollup-plugin-drupal-sdc-generator","title":"rollup-plugin-drupal-sdc-generator","description":"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.","status":"active","version":"1.1.11","language":"javascript","source_language":"en","source_url":"https://github.com/Exploratorium/rollup-plugin-drupal-sdc-generator","tags":["javascript","rollup","rollup-plugin","vite","vite-plugin","drupal"],"install":[{"cmd":"npm install rollup-plugin-drupal-sdc-generator","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-drupal-sdc-generator","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-drupal-sdc-generator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Plugin requires Rollup (or Vite's Rollup compatibility) to function; not a peer dependency but required at runtime.","package":"rollup","optional":true},{"reason":"Often used with Vite; not a direct dependency but expected in Vite projects.","package":"vite","optional":true}],"imports":[{"note":"Default export; ESM-only, CommonJS require will fail.","wrong":"const drupalSdcGenerator = require('rollup-plugin-drupal-sdc-generator')","symbol":"default","correct":"import drupalSdcGenerator from 'rollup-plugin-drupal-sdc-generator'"},{"note":"Named import is incorrect; package uses default export only.","wrong":"import { drupalSdcGenerator } from 'rollup-plugin-drupal-sdc-generator'","symbol":"drupalSdcGenerator","correct":"import drupalSdcGenerator from 'rollup-plugin-drupal-sdc-generator'"},{"note":"In Vite, the plugin must be inside rollupOptions.plugins, not top-level plugins.","wrong":"export default defineConfig({ plugins: [drupalSdcGenerator()] })","symbol":"drupalSdcGenerator (Vite usage)","correct":"import drupalSdcGenerator from 'rollup-plugin-drupal-sdc-generator';\n// in Vite config:\nexport default defineConfig({ build: { rollupOptions: { plugins: [drupalSdcGenerator()] } } })"}],"quickstart":{"code":"import drupalSdcGenerator from 'rollup-plugin-drupal-sdc-generator';\n\nexport default {\n  input: 'src/main.js',\n  output: {\n    dir: 'dist',\n    format: 'iife',\n  },\n  plugins: [\n    drupalSdcGenerator({\n      directory: 'templates', // optional: defaults to built-in templates\n    }),\n  ],\n};","lang":"javascript","description":"Minimal Rollup configuration using the plugin with optional custom template directory."},"warnings":[{"fix":"Move plugin instantiation to `build.rollupOptions.plugins` in Vite config.","message":"Vite users must place the plugin inside `build.rollupOptions.plugins`, not in the top-level `plugins` array.","severity":"gotcha","affected_versions":"all"},{"fix":"Provide a `directory` option pointing to your own templates.","message":"Template directory defaults to the plugin's internal templates; if not customized, files may be missing or unwanted.","severity":"gotcha","affected_versions":"all"},{"fix":"Escape with backslash: `\\[name\\]` to include literal `[name]`.","message":"Placeholder `[name]` in template filenames and contents is replaced; use `\\[name\\]` for literal `[name]`.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `import` syntax or dynamic `import()`.","message":"Plugin is ESM-only; `require()` throws Module not found error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use object form of `directory` to map multiple component names to their template directories.","message":"Only one component can be generated per build unless using object `directory` option.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"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).","cause":"Using CommonJS require() on an ESM-only package.","error":"Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'rollup-plugin-drupal-sdc-generator'"},{"fix":"Use `import drupalSdcGenerator from 'rollup-plugin-drupal-sdc-generator'` without curly braces.","cause":"Using named import `{ drupalSdcGenerator }` instead of default import.","error":"Error: The plugin 'rollup-plugin-drupal-sdc-generator' is not a function"},{"fix":"Move the plugin inside `build.rollupOptions.plugins` array in your Vite config.","cause":"Plugin placed in Vite's top-level `plugins` instead of inside `build.rollupOptions.plugins`.","error":"For Vite: [plugin:vite:rollup] The plugin 'rollup-plugin-drupal-sdc-generator' is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}