rollup-plugin-string

raw JSON →
3.0.0 verified Mon Apr 27 auth: no javascript maintenance

Convert text files (e.g., HTML, CSS, SVG) into ES modules for Rollup. v3.0.0 is the current stable version (no recent updates, maintenance mode). Key differentiator: lightweight, simple include/exclude patterns, no dependencies. Alternatives like rollup-plugin-glsl or rollup-plugin-stringify offer similar functionality with different features.

error Error: Cannot find module 'rollup-plugin-string'
cause Missing dependency in node_modules.
fix
npm install rollup-plugin-string --save-dev
error TypeError: string is not a function
cause Using default import instead of named import.
fix
Use { string } from 'rollup-plugin-string'
error Error: [plugin: string] Could not transform 'file.html': include pattern not set
cause No include option provided to the plugin.
fix
Pass include: '**/*.html' in plugin options.
gotcha include option is required; plugin will skip all files if missing.
fix Always specify include pattern.
gotcha The plugin only works with Rollup – not Webpack, esbuild, or Vite.
fix Use a different tool for other bundlers.
deprecated Rollup v4 is not officially tested; may break on future versions.
fix Consider using a maintained alternative if upgrading Rollup.
npm install rollup-plugin-string
yarn add rollup-plugin-string
pnpm add rollup-plugin-string

Converts all .html files (except index.html) into ES modules using Rollup.

import { rollup } from 'rollup';
import { string } from 'rollup-plugin-string';

const bundle = await rollup({
  input: 'main.js',
  plugins: [
    string({
      include: '**/*.html',
      exclude: '**/index.html'
    })
  ]
});

const { code } = await bundle.generate({ format: 'esm' });
console.log(code);