Registry / devops / rollup-plugin-static-import

rollup-plugin-static-import

JSON →
library1.0.0jsnpmunverified

Rollup plugin that copies imported files (e.g., SVG, SCSS) to the output directory while marking them as external in the bundle. Version 1.0.0 rewrites in TypeScript with type declarations. Best used with rollup's preserveModules option to keep imports tree-shakable. Unlike generic copy plugins, it integrates with rollup's watch mode and handles asset re-imports. Requires rollup ^1.20.0 || ^2.0.0 || ^3.0.0.

npm install rollup-plugin-static-import
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-STAT
R
rollup-plugin-static-import
devopsjavascriptv1.0.0
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
import staticImport from 'rollup-plugin-static-import'
const staticImport = require('rollup-plugin-static-import')
ESM-only; CommonJS require will fail because the package exports only ESM since v1.0.0. Use dynamic import or configure bundler to handle it.
StaticImportOptions
import type { StaticImportOptions } from 'rollup-plugin-static-import'
import { StaticImportOptions } from 'rollup-plugin-static-import'
Type-only export; importing as value will be undefined at runtime. Use 'import type' in TypeScript.
Plugin
import { Plugin } from 'rollup'
import { Plugin } from 'rollup-plugin-static-import'
rollup-plugin-static-import does not re-export rollup types; get Plugin from rollup itself.

Configures rollup to copy SVG and SCSS files from src to dist, marking them as external so the consuming app bundles them.

// rollup.config.js import staticImport from 'rollup-plugin-static-import'; export default { input: 'src/index.js', preserveModules: true, output: { dir: 'dist', format: 'esm' }, plugins: [ staticImport({ include: ['src/**/*.svg', 'src/**/*.scss'], exclude: ['src/**/*.test.*'], baseDir: 'src' }) ] };
Debug
Known issues
gotchaUsing staticImport without preserveModules: true may produce non-tree-shakable bundles where all assets are inlined into a single chunk.
fix
Set preserveModules: true in rollup config.
affects: >=0.0.0
deprecatedThe 'include' option is required; omitting it will cause a runtime error.
fix
Always provide include with at least one glob pattern.
affects: >=1.0.0
breakingv1.0.0 switched to ESM-only output. CommonJS require() will throw ERR_REQUIRE_ESM.
fix
Use dynamic import() or configure your bundler to handle ESM. If using CommonJS, stay on v0.x.
affects: >=1.0.0
gotchaPlugin copies files based on import paths relative to baseDir; incorrect baseDir leads to wrong output paths.
fix
Set baseDir to the directory relative to which you want files copied. Default is 'src'.
affects: >=0.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/rollup-plugin-static-import/dist/index.js from /path/to/rollup.config.js not supported.
Package is ESM-only since v1.0.0; CommonJS require() cannot load it.
fix
Use import syntax in your config file (if rollup supports it) or switch to dynamic import: const staticImport = (await import('rollup-plugin-static-import')).default;
TypeError: staticImport is not a function
Named import instead of default import: import { staticImport } from 'rollup-plugin-static-import'
fix
Use default import: import staticImport from 'rollup-plugin-static-import'
The plugin staticImport did not output any files under output dir. (No files to copy?)
include globs matched no files, or baseDir/resolveRoot misconfigured.
fix
Verify that include patterns match files relative to projectRoot (default cwd) or adjust projectRoot option.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
rolluprequiredpeer dependency; plugin API used
Agent activity
8 hits · last 30 days
node
8
Resources
rollup-plugin-static-import — npm install rollup-plugin-static-import · libregistry