Registry / devops / prettier-plugin-bootstrap

prettier-plugin-bootstrap

JSON →
library0.3.0jsnpmunverified

A Prettier plugin that automatically sorts Bootstrap CSS classes following the framework's recommended order (layout → components → utilities). Current stable version is 0.3.0, released May 2026, with regular releases. Key differentiators: zero configuration, works with multiple template engines (HTML, JSX/TSX, Vue, Angular, Svelte, Astro), supports custom attributes and functions like clsx, and preserves unknown classes. Requires Prettier ^3.0.0 and Node >=20. Offers options for attribute matching (regex), whitespace preservation, duplicate handling, and version targeting.

npm install prettier-plugin-bootstrap
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-BO
P
prettier-plugin-bootstrap
devopsjavascriptv0.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import prettierPluginBootstrap from 'prettier-plugin-bootstrap'
✗ const prettierPluginBootstrap = require('prettier-plugin-bootstrap')
Plugin is ESM-only. For CJS, use dynamic import().
options
✓ { "plugins": ["prettier-plugin-bootstrap"], "bootstrapFunctions": ["clsx"] }
Configure in .prettierrc or prettier.config.js. Options are NOT importable symbols.
Plugin
✓ import { type Plugin } from 'prettier'; import bootstrapPlugin from 'prettier-plugin-bootstrap'; const plugin: Plugin = bootstrapPlugin;
TypeScript types are shipped; the default export is typed as Plugin.

Shows installation, configuration with options, and the sorting result on an HTML file.

// Install: npm install -D prettier prettier-plugin-bootstrap // .prettierrc { "plugins": ["prettier-plugin-bootstrap"], "bootstrapFunctions": ["clsx", "cn"], "bootstrapAttributes": ["/^data-class/"], "bootstrapPreserveDuplicates": false } // Input file (test.html) <div class="text-center p-3 container bg-primary text-white mb-4 rounded"></div> // Run: npx prettier --write test.html // Output: <div class="container bg-primary text-center text-white mb-4 p-3 rounded"></div>
Debug
Known issues
breakingVersion 0.3.0 changed plugin export to ESM-only; CJS require() will fail.
fix
Use dynamic import(): const plugin = await import('prettier-plugin-bootstrap'); or set type: module.
affects: >=0.3.0
gotchabootstrapPreserveWhitespace: false normalizes whitespace, which may affect formatting in JSX/TSX if you rely on whitespace for readability.
fix
Set bootstrapPreserveWhitespace: true if original spacing is important.
affects: >=0.1.0
deprecatedbootstrapVersion option currently only accepts 5; future versions may support 4.
fix
Set bootstrapVersion: 5 for now.
affects: >=0.1.0
gotchaPlugin requires Prettier ^3.0.0; will not work with Prettier 2.x.
fix
Upgrade to Prettier 3.x: npm install -D prettier@^3.0.0
affects: >=0.1.0
gotchaRegex in bootstrapAttributes must match the entire attribute name, not partial.
fix
Use full pattern like /^data-class/ or an exact string.
affects: >=0.3.0
gotchaDuplicate classes are kept by default (bootstrapPreserveDuplicates: true). This may cause unexpected results if duplicates are unintentional.
fix
Set bootstrapPreserveDuplicates: false to remove duplicates.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'prettier-plugin-bootstrap'
Plugin not installed or not in node_modules.
fix
Run: npm install -D prettier-plugin-bootstrap
Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/prettier-plugin-bootstrap/...
Using CommonJS require() with an ESM-only plugin (v0.3.0+).
fix
Use dynamic import: const plugin = await import('prettier-plugin-bootstrap'); or set "type": "module" in package.json.
TypeError: prettier.resolveConfig.sync is not a function
Using Prettier 2.x API; plugin requires Prettier 3.x.
fix
Upgrade to Prettier 3.x: npm install -D prettier@^3
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
prettierrequiredpeer dependency; plugin requires Prettier ^3.0.0
Agent activity
2 hits · last 30 days
node
2
Resources
prettier-plugin-bootstrap — npm install prettier-plugin-bootstrap · libregistry