rollup-plugin-prepack
raw JSON → 1.1.1 verified Mon Apr 27 auth: no javascript maintenance
Rollup plugin that integrates Facebook Prepack (version 0.2.54+ peer dependency) to optimize JavaScript bundles at build time by running Prepack, a partial evaluator that produces smaller, faster code. Version 1.1.1 is the latest stable release; the project appears to be in maintenance mode with no recent commits. Key differentiator: enables ahead-of-time optimization via Prepack within the Rollup pipeline, unlike general minifiers.
Common errors
error Cannot find module 'rollup-plugin-prepack' ↓
cause Package not installed or mismatched peer dependency prepack not found.
fix
Run npm install rollup-plugin-prepack prepack --save-dev
error Error: Prepack failed with: ... ↓
cause Prepack encountered unsupported syntax or errors in the input code.
fix
Check Prepack compatibility; validate input code with Prepack CLI standalone.
Warnings
deprecated Facebook Prepack is no longer actively maintained and may not work with modern JavaScript features. ↓
fix Consider alternative optimizers like Google Closure Compiler or esbuild-plugin-prepack.
gotcha Prepack requires the input code to be compatible; it may throw errors for unsupported syntax (e.g., dynamic imports, eval). ↓
fix Ensure input code is compatible with Prepack's supported subset, or use babel plugin to transpile beforehand.
breaking Version 1.0.0 switched from CommonJS to ESM-only exports; require() will fail. ↓
fix Use import syntax or upgrade to Node 13+ with --experimental-modules (legacy).
Install
npm install rollup-plugin-prepack yarn add rollup-plugin-prepack pnpm add rollup-plugin-prepack Imports
- default (prepack) wrong
const prepack = require('rollup-plugin-prepack')correctimport prepack from 'rollup-plugin-prepack' - prepack (as Rollup plugin) wrong
import { prepack } from 'rollup-plugin-prepack'correctimport prepack from 'rollup-plugin-prepack' - PluginOptions
import type { PluginOptions } from 'rollup-plugin-prepack'
Quickstart
import prepack from 'rollup-plugin-prepack';
export default {
input: 'src/index.js',
output: {
file: 'dist/optimized.js',
format: 'cjs'
},
plugins: [
prepack({
// Optional Prepack options
timeout: 10000,
mathRandomSeed: '0'
})
]
};