Skip to content

fix(vite): add library mode build, declare React external, document C… - #155

Merged
k-deejah merged 1 commit into
Sorokit:mainfrom
BernardOnuh:fix/vite-library-build
Jun 27, 2026
Merged

fix(vite): add library mode build, declare React external, document C…#155
k-deejah merged 1 commit into
Sorokit:mainfrom
BernardOnuh:fix/vite-library-build

Conversation

@BernardOnuh

@BernardOnuh BernardOnuh commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes issue by adding proper Vite library build configuration and resolving three critical packaging issues:

  1. No library mode build - npm run build produced HTML app instead of redistributable library
  2. React not declared external - caused "multiple React instances" errors in consumer apps
  3. No CSS setup documentation - consumers couldn't use Tailwind utilities

Problems Fixed

1. ❌ No build.lib Entry

  • Before: npm run builddist/index.html (app bundle)
  • After: npm run builddist/sorokit-ui.es.js + dist/sorokit-ui.cjs.js (library bundle)
  • Impact: Package couldn't be published to npm; consumers couldn't use it

2. ❌ React Not Declared External

  • Before: React bundled inside library
  // dist/sorokit-ui.es.js includes entire React
  // Consumer app also has React
  // Result: Two React instances, hooks break
  • After: React declared external
  // dist/sorokit-ui.es.js imports React
  import React from 'react'
  // Consumer provides React
  // Result: Single React instance, everything works
  • Impact: "Multiple React instances" errors in consumer apps

3. ❌ No CSS/Tailwind Documentation

  • Before: No guidance on CSS setup for consumers
  • After: Complete CSS setup documentation with 3 options:
    • Tailwind CSS (recommended)
    • CSS Modules (alternative)
    • Custom styling (override)
  • Impact: Consumers didn't know how to import styles

Changes

  • ✅ Add build.lib configuration to vite.config.ts
  • ✅ Add rollupOptions.external for React dependencies
  • ✅ Create vite.lib.config.ts for dedicated library builds
  • ✅ Create src/components/index.ts for clean exports
  • ✅ Update package.json with proper export fields
  • ✅ Add tsconfig.lib.json for TypeScript definitions
  • ✅ Add CSS Setup section to README
  • ✅ Add build output tests

Files Changed

  • vite.config.ts - Added library build configuration
  • vite.lib.config.ts - New file for library-only builds
  • src/components/index.ts - New file for component exports
  • package.json - Added main/module/types/exports fields
  • tsconfig.lib.json - New TypeScript config for declarations
  • src/__tests__/build.test.ts - Tests for build output
  • README.md - Added CSS Setup section

Build Output

Closes #104

Before

…SS setup

Fixes Sorokit#104

- Add build.lib configuration to vite.config.ts with proper entry point
- Add rollupOptions.external for React, ReactDOM, react/jsx-runtime
- Create vite.lib.config.ts for dedicated library builds
- Add component index (src/components/index.ts) for clean exports
- Update package.json with proper main/module/types/exports fields
- Add tsconfig.lib.json for declaration-only compilation
- Add CSS setup documentation to README (Tailwind, CSS Modules, custom)
- Add build output tests verifying ES/CJS modules and no React bundling

npm run build now produces:
- dist/sorokit-ui.es.js (ES modules)
- dist/sorokit-ui.cjs.js (CommonJS)
- dist/index.d.ts (TypeScript definitions)
- dist/style.css (Compiled styles)
@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@BernardOnuh Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@k-deejah
k-deejah merged commit 3052ad1 into Sorokit:main Jun 27, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(vite): no library mode build, React not declared external, no CSS setup docs for consumers

2 participants