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.
Common errors
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).
Warnings
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.
Install
npm install rollup-plugin-raw yarn add rollup-plugin-raw pnpm add rollup-plugin-raw Imports
- raw wrong
import { raw } from 'rollup-plugin-raw'correctimport raw from 'rollup-plugin-raw' - raw wrong
const { raw } = require('rollup-plugin-raw')correctconst raw = require('rollup-plugin-raw') - raw wrong
import raw from 'rollup-plugin-raw/index.js'correctimport raw from 'rollup-plugin-raw'
Quickstart
// 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'