Export AI Rules from NPM Packages
Learn how to export AI rules from your NPM packages so users can install them with vibe-rules.
Overview
As AI becomes more integrated into development workflows, reusable AI rules and prompts are becoming valuable shared assets. By exporting rules from your NPM packages, you can help developers get up to speed with your library's best practices quickly.
vibe-rules looks for an llms
export in your package that contains rule definitions compatible with various AI-powered editors.
Package Setup
1. Configure package.json
Add an llms
export to your package.json:
Note: You can also use a simple string export: "./llms": "./dist/llms.js"
2. Create Rules File
Create your rules file that exports an array of rule definitions:
ESM Example (src/llms.mjs):
CommonJS Example (src/llms.cjs):
Rule Format Reference
Rule Object Schema
name
A unique identifier for the rule. Will be prefixed with your package name when installed.
rule
The actual rule content - this is what gets applied to the editor. Can be markdown formatted.
alwaysApply (Optional)
For Cursor editor: when true
, the rule is automatically applied to all files. When false
or omitted, it's applied based on context.
globs (Optional)
File patterns to match. Can be a single string or array of strings. Examples: "src/**/*.ts"
, ["**/*.test.js", "**/*.spec.js"]
Build Process
Make sure your build process generates the llms files in the correct format and location:
Tip: You can also use a bundler like Rollup or esbuild to generate both CommonJS and ESM versions automatically.
Testing Your Rules
Local Testing
Test your rules locally before publishing:
Validation
vibe-rules validates your rule exports using Zod schemas. Common issues:
Missing required fields: Make sure rule objects have name
and rule
properties.
Wrong export format: Export should be an array of strings/objects, not a single object.
Invalid globs: Globs should be strings or arrays of strings, not other types.
Best Practices
Clear Rule Names
Use descriptive names like "api-guidelines" or "testing-patterns" rather than generic names like "rule1".
Specific File Patterns
Use precise glob patterns to ensure rules only apply to relevant files. Avoid overly broad patterns like "**/*"
.
Meaningful Descriptions
Add descriptions to help users understand when and why to use each rule.
Use alwaysApply Sparingly
Only set alwaysApply: true
for fundamental rules that should always be considered.
Complete Example
Example: React Component Library
Publishing
Once your rules are ready, publish your package normally:
Users can then install your rules with:
Documentation: Consider adding a section to your README explaining that your package exports AI rules that can be installed with vibe-rules.