rollup-plugin-ignore-import
raw JSON → 1.3.2 verified Mon Apr 27 auth: no javascript
Rollup plugin to ignore imports based on file extensions (e.g., .css, .scss) during bundling, replacing them with a configurable stub. Version 1.3.2 is the latest stable release. The plugin uses rollup-pluginutils for filtering and supports both extension and include patterns. It's useful in test environments or when you want to exclude static assets from the bundle without ejecting. Unlike rollup-plugin-string or inject, this plugin fully removes the import and substitutes a default export.
Common errors
error Error: Cannot find module 'rollup-pluginutils' ↓
cause rollup-pluginutils is listed as a peer dependency but not installed automatically by npm/yarn in some configurations.
fix
Run
npm install rollup-pluginutils --save-dev or add it to devDependencies manually. error ReferenceError: exports is not defined ↓
cause Using CJS require in an ESM context (e.g., "type": "module" in package.json).
fix
Use
import ignoreImport from 'rollup-plugin-ignore-import' instead of require. error TypeError: ignoreImport is not a function ↓
cause Destructuring the default export incorrectly.
fix
Change
import { ignoreImport } from 'rollup-plugin-ignore-import' to import ignoreImport from 'rollup-plugin-ignore-import'. Warnings
breaking The package requires rollup-pluginutils as a peer dependency, which may not be automatically installed with newer Rollup versions. This can cause 'Cannot find module 'rollup-pluginutils'' errors. ↓
fix Install rollup-pluginutils explicitly: npm install rollup-pluginutils --save-dev. Or use rollup-plugin-ignore-import@2.0.0 (if available) that may have dropped this dependency.
gotcha The plugin replaces ignored imports with a default export of `undefined` by default. If you rely on the import to have a specific shape (e.g., CSS modules), the replacement may cause runtime errors. ↓
fix Specify a `body` option that matches what your code expects, e.g., `body: 'export default {};'` for CSS modules.
deprecated The `include` and `exclude` options accept glob patterns but are handled by rollup-pluginutils's createFilter, which does not support negative patterns (like `!**/*.css`). Use `extensions` instead for simpler cases. ↓
fix Use `extensions: ['.css']` instead of `include: ['**/*.css']`. If you need exclude, consider a different plugin like rollup-plugin-filter.
Install
npm install rollup-plugin-ignore-import yarn add rollup-plugin-ignore-import pnpm add rollup-plugin-ignore-import Imports
- ignoreImport wrong
import { ignoreImport } from 'rollup-plugin-ignore-import'correctimport ignoreImport from 'rollup-plugin-ignore-import' - ignoreImport wrong
const { ignoreImport } = require('rollup-plugin-ignore-import')correctconst ignoreImport = require('rollup-plugin-ignore-import') - Plugin (type) wrong
import type { Plugin } from 'rollup-plugin-ignore-import'correctimport type { Plugin } from 'rollup'
Quickstart
// rollup.config.js
import ignoreImport from 'rollup-plugin-ignore-import';
import resolve from '@rollup/plugin-node-resolve';
export default {
input: 'src/index.js',
output: { dir: 'dist', format: 'esm' },
plugins: [
resolve(),
ignoreImport({
extensions: ['.css', '.scss'],
body: 'export default "ignored";'
})
]
};
// Input src/index.js
import './style.css';
console.log('Hello');
// Output dist/index.js will have no import for style.css; the import is replaced with `const style = "ignored";` (or similar).