rollup-plugin-preprocess
raw JSON → 0.0.4 verified Mon Apr 27 auth: no javascript deprecated
A Rollup plugin that integrates the Preprocess library to conditionally include or exclude parts of files (HTML, JS, etc.) based on a user-defined context (e.g., DEBUG flags). The latest stable version is 0.0.4 (released November 2016). Development appears to be stalled with no recent releases or maintenance; this plugin is a thin wrapper around the `preprocess` package for Rollup build pipelines. Alternatives include `@rollup/plugin-replace` or direct use of `preprocess` with other Rollup hooks. The plugin supports simple context-based preprocessing but lacks extensive documentation and has limited adoption.
Common errors
error Error: Cannot find module 'rollup-pluginutils' ↓
cause Missing dependency rollup-pluginutils which is a peer dependency.
fix
npm install rollup-pluginutils --save-dev
error TypeError: preprocess is not a function ↓
cause Using named import when only default export exists.
fix
Use import preprocess from 'rollup-plugin-preprocess' instead of import { preprocess } from 'rollup-plugin-preprocess'
Warnings
deprecated This package has not been updated since 2016 and is essentially unmaintained. Consider using modern alternatives like @rollup/plugin-replace. ↓
fix Migrate to @rollup/plugin-replace or use the preprocess library directly with a custom Rollup plugin.
gotcha The plugin does not handle TypeScript or Vue files out-of-the-box; you may need to adjust the include/exclude filter. ↓
fix Manually specify the include and exclude options in the plugin configuration.
gotcha The context object is not deeply merged; only top-level properties are available in preprocess directives. ↓
fix Pass nested values as flat keys or use a string expression that evaluates in the preprocess context.
Install
npm install rollup-plugin-preprocess yarn add rollup-plugin-preprocess pnpm add rollup-plugin-preprocess Imports
- default wrong
const preprocess = require('rollup-plugin-preprocess').defaultcorrectimport preprocess from 'rollup-plugin-preprocess' - RollupPluginPreprocess wrong
import { RollupPluginPreprocess } from 'rollup-plugin-preprocess'correctimport RollupPluginPreprocess from 'rollup-plugin-preprocess'
Quickstart
// rollup.config.js
import preprocess from 'rollup-plugin-preprocess';
export default {
input: 'src/main.js',
output: {
file: 'dist/bundle.js',
format: 'iife'
},
plugins: [
preprocess({
context: {
DEBUG: process.env.DEBUG === 'true',
VERSION: '1.0.0'
}
})
]
};
// In your source code:
// @if DEBUG
console.log('Debug mode');
// @endif
// @echo VERSION