build command builds components for a shadcn/ui registry. Use it to create a custom registry by bundling your component files into registry JSON files.
Usage
Arguments
string
default:"./registry.json"
Path to the registry.json file. Defaults to
./registry.json in the current directory.Options
string
default:"./public/r"
Destination directory for JSON files. Defaults to
./public/r.string
The working directory. Defaults to the current directory.
Examples
Build with default paths
./registry.json to ./public/r.
Build from custom registry file
Build to custom output directory
Build with custom paths
Build in specific directory
What it does
- Reads the
registry.jsonfile - Validates the registry schema
- For each registry item:
- Reads the source files from disk
- Embeds file content into the registry item
- Adds the JSON schema URL
- Validates the complete registry item
- Writes a JSON file to the output directory
- Copies
registry.jsonto the output directory
Registry structure
Yourregistry.json should follow this structure:
Output structure
After building, your output directory will contain:Registry item fields
Each item inregistry.json can include:
string
required
Unique identifier for the component.
string
required
Registry type:
registry:ui, registry:block, registry:hook, registry:lib, etc.array
required
Array of file objects with
path and optional type.array
npm packages required by the component.
array
npm dev packages required by the component.
array
Other registry components required by this component.
object
Additional metadata (description, tags, etc.).
Creating a custom registry
1. Create registry.json
2. Build the registry
3. Serve the registry
Deploy thepublic/r directory to a web server or CDN.
4. Use the registry
Add tocomponents.json:
Validation
The build command validates:- Registry schema - Ensures
registry.jsonis valid - Registry item schema - Validates each component’s metadata
- File existence - Checks that all referenced files exist
- Log an error message
- Skip the invalid item
- Continue building other items
Use cases
Internal component library
Build a private registry for your organization:Open source components
Share your components publicly:Monorepo packages
Build registries for multiple packages:Output
Error handling
Invalid registry file
Invalid registry item
File not found
If a referenced file doesn’t exist, the build will fail. Ensure all paths infiles arrays are correct and relative to the cwd.
Notes
- File paths in
registry.jsonshould be relative to the working directory - The build embeds full file content, so output files can be large
- Output is production-ready JSON for hosting
- Schema URLs are automatically added to built files
- Original
registry.jsonis copied to output directory - Safe to run multiple times (overwrites previous build)