A Vite plugin (v1.0.2) that transforms `<If>`, `<Choose>`, `<When>`, and `<Otherwise>` JSX components into native JavaScript ternary/conditional expressions at build time, avoiding runtime overhead. Inspired by jsx-control-statements and Svelte logic blocks. Provides type definitions via `vite-plugin-react-control-statements` and optional global types via `@types/vite-plugin-react-control-statements`. Uses regex-based transformation, which is imperfect for complex nested cases. Compatible with React, Vue, and any JSX/TSX setup in Vite. Active development with no recent updates; known issues with regex parsing.
npm install vite-plugin-react-control-statementsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows plugin setup in vite.config.ts and usage of If/Choose/When/Otherwise in a React component.
Avoid deeply nested <If> inside <If> or <When> inside <When>. Consider manual ternary for complex logic.
Install with `npm i -D @types/vite-plugin-react-control-statements` if you want global types without explicit imports.
Use real JSX conditional logic if you need dynamic condition re-evaluation.
Use jsx-control-statements for Webpack projects.
Ensure package is installed: `npm i vite-plugin-react-control-statements` and add to tsconfig.json: `"types": ["vite-plugin-react-control-statements"]`
Ensure plugin is added to vite.config.ts: `import reactControlStatements from 'vite-plugin-react-control-statements'; plugins: [react(), reactControlStatements()]`
Install type declarations: `npm i -D @types/vite-plugin-react-control-statements` and add `/// <reference types="vite-plugin-react-control-statements" />` in a global.d.ts file.
No dependency data recorded yet.