Package Tansy UI as @openkhalix/tansy-ui in a monorepo (v0.4.0)
Restructure the repo into npm workspaces so the component kit publishes as its own package, like MUI and shadcn/ui: - packages/ui: @openkhalix/tansy-ui (published), with components, stories, tests, tokens and the library build - packages/brand: private logo and catalogue data shared by both apps - apps/site: the landing page - apps/docs: Storybook The package: - MIT licence (copyright OpenKhalix) - per-component ES modules and type declarations - "use client" on component modules so they import into Next.js Server Components; helpers stay server-safe - tokens.css for Tailwind v4 apps, and a prebuilt styles.css for apps without Tailwind - lucide-react 1.x, whose types compile against current React 19 types The apps resolve the package through a "source" export condition, so they hot-reload component edits, while outside users get dist/. scripts/test-package.mjs packs the package and installs the tarball into Vite + Tailwind (strict types), plain React and Next.js apps; each must build and render correctly. Gitea workflows run CI on push and publish to npm when a vX.Y.Z tag matching the package version is pushed.
This commit is contained in:
1 parent
23e67006d3
commit
9255b255a6
214 files changed
+1521
-389
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
/**
|
||||
* Library build: `npm run build` → dist/.
|
||||
*
|
||||
* One ES module per source file (preserveModules), so apps only bundle the
|
||||
* components they import. Dependencies stay external. Types come from
|
||||
* `tsc -p tsconfig.lib.json`; tokens.css and styles.css are added by the
|
||||
* build script.
|
||||
*/
|
||||
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')) as {
|
||||
version: string
|
||||
dependencies: Record<string, string>
|
||||
peerDependencies?: Record<string, string>
|
||||
}
|
||||
const external = [...Object.keys(pkg.dependencies), ...Object.keys(pkg.peerDependencies ?? {})]
|
||||
|
||||
/**
|
||||
* Component modules use hooks, so React Server Components must treat them as
|
||||
* client code. Pure helpers (cn, applyPalette, style maps) stay unmarked so a
|
||||
* server component can still call them.
|
||||
*/
|
||||
function isClientModule(fileName: string) {
|
||||
return (
|
||||
fileName.startsWith('components/') &&
|
||||
!fileName.endsWith('.tokens.js') &&
|
||||
!fileName.endsWith('.fixtures.js')
|
||||
)
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
define: {
|
||||
__TANSY_VERSION__: JSON.stringify(pkg.version),
|
||||
},
|
||||
plugins: [react()],
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
emptyOutDir: true,
|
||||
sourcemap: true,
|
||||
copyPublicDir: false,
|
||||
lib: {
|
||||
entry: fileURLToPath(new URL('./src/index.ts', import.meta.url)),
|
||||
formats: ['es'],
|
||||
},
|
||||
rollupOptions: {
|
||||
external: (id) => external.some((dep) => id === dep || id.startsWith(`${dep}/`)) || id.startsWith('react/'),
|
||||
output: {
|
||||
preserveModules: true,
|
||||
preserveModulesRoot: 'src',
|
||||
entryFileNames: '[name].js',
|
||||
banner: (chunk) => (isClientModule(chunk.fileName) ? "'use client';" : ''),
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user