rollup-plugin-raw

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

Rollup plugin that transforms raw text files (e.g., .txt, .glsl, .fs) into ES modules that export the file content as a string. Current stable version is 0.0.1, requiring Node.js v14+ and Rollup v3+. Lightweight and minimal, with TypeScript type definitions included. Differentiators: simple regex-based filtering, no dependencies.

error Error: Cannot find module 'rollup-plugin-raw'
cause Plugin not installed or missing from node_modules.
fix
Run 'pnpm add rollup-plugin-raw -D' or 'npm install --save-dev rollup-plugin-raw'.
error TypeError: raw is not a function
cause Using named import instead of default import.
fix
Use 'import raw from 'rollup-plugin-raw'' (default import).
gotcha Plugin requires Rollup v3.0.0+ and Node v14.0.0+. Using older versions will cause errors.
fix Upgrade Rollup to >=3.0.0 and Node to >=14.0.0.
gotcha The plugin is extremely early (v0.0.1); API may change without major semver bump.
fix Pin exact version and test upgrades.
npm install rollup-plugin-raw
yarn add rollup-plugin-raw
pnpm add rollup-plugin-raw

Configures Rollup to import raw text files as strings using rollup-plugin-raw.

// rollup.config.js
import { defineConfig } from 'rollup';
import raw from 'rollup-plugin-raw';

export default defineConfig({
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'es'
  },
  plugins: [
    raw({
      filter: /\.(txt|glsl|fs)$/i
    })
  ]
});

// src/test.txt
hello world

// src/index.js
import txt from './test.txt';
console.log(txt); // 'hello world'