Registry / devops / rollup-plugin-inline-code

rollup-plugin-inline-code

JSON →
library1.2.7jsnpmunverified

A Rollup plugin that loads files as plain text strings, akin to Webpack's raw-loader, using a configurable import prefix (default 'inline!'). Version 1.2.7 is the current stable release, published via semantic-release with automated versioning. It supports Node.js 12–16 and works with JavaScript, TypeScript, SVG, and any text-based assets. The plugin integrates seamlessly into Rollup builds, enabling inline injection of file contents into generated bundles—a common pattern in server-side rendering or HTML template generation. Unlike similar plugins, it uses a distinctive import prefix syntax to differentiate inline imports from standard module imports.

npm install rollup-plugin-inline-code
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-INLI
R
rollup-plugin-inline-code
devopsjavascriptv1.2.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export
import inlineCode from 'rollup-plugin-inline-code'
const inlineCode = require('rollup-plugin-inline-code')
The package exports a single default function; named import is not supported.
Imported file content
import content from 'inline!./path/to/file.js'
import content from './path/to/file.js'
Must use the 'inline!' prefix in the import source to trigger the plugin.
TypeScript type declaration
declare module 'inline!*' { const inlineCode: string; export default inlineCode; }
declare module 'inline!*' { export = string; }
Required for TypeScript projects to avoid import errors. Place in a .d.ts file.

Shows basic Rollup setup with plugin and usage of the inline prefix to import a JavaScript file's raw content.

// rollup.config.js import inlineCode from 'rollup-plugin-inline-code'; export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'iife' }, plugins: [inlineCode()] }; // src/index.js import scriptContent from 'inline!./inline.js'; console.log(scriptContent); // src/inline.js // This file will be read as text const greeting = 'Hello from inline!';
Debug
Known issues
gotchaThe plugin only transforms imports with the configured prefix (default 'inline!'). Regular imports are unaffected.
fix
Always prepend the prefix to import sources intended for inlining.
affects: *
gotchaTypeScript users must declare a module for 'inline!*' to avoid type errors.
fix
Add a global module declaration: declare module 'inline!*' { const inlineCode: string; export default inlineCode; }
affects: *
gotchaThe plugin returns a string, not a module; you cannot destructure or use named exports from the imported content.
fix
Use default import syntax: import x from 'inline!./file.js'
affects: *
gotchaSemver range for peer dependency rollup is not specified; may break with future Rollup major versions.
fix
Check compatibility with your Rollup version; restrict to known working versions.
affects: *
Errors
Common errors & fixes
Error: Could not resolve 'inline!./path/to/file.js'
Rollup cannot resolve the module because the plugin is not properly configured or the prefix is missing.
fix
Ensure the plugin is added to the plugins array in rollup.config.js and that the import source starts with 'inline!'.
Cannot find module 'rollup-plugin-inline-code' or its corresponding type declarations.
Package is not installed or TypeScript type declarations are missing.
fix
Run 'npm install rollup-plugin-inline-code' and add a global module declaration for 'inline!*'.
TS2307: Cannot find module 'inline!./file.svg' or its corresponding type declarations.
TypeScript cannot resolve the module because the declaration is missing.
fix
Add 'declare module "inline!*" { const inlineCode: string; export default inlineCode; }' to a .d.ts file.
Upgrade
Version history
1.2.7latest on npm
Audit
Dependencies
rolluprequiredPeer dependency, plugin requires Rollup to function.
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
2
Resources
rollup-plugin-inline-code — npm install rollup-plugin-inline-code · libregistry