Vite CPAT
raw JSON → 0.1.9 verified Mon Apr 27 auth: no javascript
Vite plugin for compiling .cpat files (Clarity Pattern files) using clarity-pattern-parser. Current stable version is 0.1.9. The plugin integrates with Vite's build pipeline to parse .cpat files and export patterns as JavaScript modules. Low release cadence, requires TypeScript module augmentation for type safety. Alternative to manual parsing workflows, designed specifically for Vite projects.
Common errors
error Cannot find module 'vite-cpat' or its corresponding type declarations. ↓
cause Missing installation or TypeScript not configured for ESM resolution.
fix
Install the package and ensure 'moduleResolution' is set to 'node16' or 'bundler' in tsconfig.json
error Module '"*.cpat"' resolves to a non-module entity and cannot be imported using this construct. ↓
cause Missing module declaration for .cpat files in a TypeScript project.
fix
Add the declare module '*.cpat' block from the README to a global .d.ts file
Warnings
gotcha Plugin expects clarity-pattern-parser as a peer dependency; must be installed separately. ↓
fix Install clarity-pattern-parser: yarn add clarity-pattern-parser
gotcha TypeScript projects require a module declaration for '*.cpat' imports; omitted by default. ↓
fix Add declare module '*.cpat' { ... } as shown in README
breaking ESM-only; does not support CommonJS require() syntax. ↓
fix Use import syntax instead of require()
Install
npm install vite-cpat yarn add vite-cpat pnpm add vite-cpat Imports
- default wrong
const cpat = require('vite-cpat')correctimport cpat from 'vite-cpat' - Pattern wrong
import { Pattern } from 'vite-cpat'correctimport type { Pattern } from 'clarity-pattern-parser' - .cpat module declaration wrong
declare module '*.cpat' { export default Record<string, Pattern> }correctdeclare module '*.cpat' { ... }
Quickstart
import { defineConfig } from 'vite';
import cpat from 'vite-cpat';
export default defineConfig({
plugins: [cpat()],
});