Registry / web-framework / rollup-plugin-preact

rollup-plugin-preact

JSON →
library0.5.2jsnpmunverified

Rollup plugin that automatically resolves and aliases React imports to Preact/Preact Compat in Rollup bundles. Current stable version 0.5.2. Configurable options include usePreactX for Preact X, noPropTypes, noReactIs, noEnv flags to remove unnecessary compat code, and custom aliasModules. It simplifies migrating from React to Preact by handling module resolution and compat aliasing.

npm install rollup-plugin-preact
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-PREA
R
rollup-plugin-preact
web-frameworkjavascriptv0.5.2
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.

preact
import preact from 'rollup-plugin-preact'
const preact = require('rollup-plugin-preact').default
Package defaults to default export; CJS require works directly, but ESM import is preferred.
preact (CommonJS)
const preact = require('rollup-plugin-preact')
No default property needed; the default export is the plugin function.
plugin usage in rollup.config.js
import preact from 'rollup-plugin-preact'; export default { plugins: [preact({ usePreactX: true })] }
export default { plugins: [preact.default()] }
preact is a function, not an object with a default method.

Configure Rollup to replace React imports with Preact/Preact Compat and remove unnecessary compat code.

// rollup.config.js import preact from 'rollup-plugin-preact'; export default { input: 'src/main.js', output: { file: 'bundle.js', format: 'iife', }, plugins: [ preact({ usePreactX: true, noPropTypes: true, noReactIs: true, noEnv: true, resolvePreactCompat: true, aliasModules: { 'react-dom': 'preact/compat', }, }), ], };
Debug
Known issues
breakingVersion 0.5.x drops support for Node < 10; requires Rollup >= 1.0
fix
Upgrade Node to >=10 and Rollup to >=1.0.
affects: >=0.5.0
deprecatedOption 'usePreactX' is deprecated in favor of using 'resolvePreactCompat: true' with Preact X+.
fix
Replace 'usePreactX: true' with 'resolvePreactCompat: true'.
affects: <0.5.0
gotchaPlugin does not automatically install Preact; you must install 'preact' and optionally 'preact/compat'.
fix
Run 'npm install preact' and use 'aliasModules: { "react": "preact/compat" }'.
affects: >=0.0.0
gotchaWhen using 'noPropTypes', ensure your code does not rely on PropTypes (runtime removal may cause errors).
fix
Remove PropTypes imports or set 'noPropTypes: false' if needed.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'rollup-plugin-preact'
Package not installed or not in node_modules.
fix
Run 'npm install rollup-plugin-preact' or 'yarn add rollup-plugin-preact'.
TypeError: preact is not a function
Importing incorrectly (e.g., preact.default()).
fix
Use 'import preact from "rollup-plugin-preact"' or 'const preact = require("rollup-plugin-preact")'.
Error: No version of preact/compat found in node_modules
Preact Compat not installed or alias not configured correctly.
fix
Install preact-compat or set alias properly, e.g., 'aliasModules: { "react": "preact/compat" }'.
Upgrade
Version history
0.5.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-preact — npm install rollup-plugin-preact · libregistry