From 60ce6025f26f1a6045797aecb7c2268898797b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Pern=C3=ADk?= Date: Mon, 1 Apr 2024 16:06:00 +0200 Subject: [PATCH] Split parts into subpackages --- .github/workflows/release.yml | 11 +++++++---- package.json | 3 +-- src/components/index.ts | 2 ++ src/index.d.ts | 3 +++ src/index.ts | 5 ----- vite.config.ts | 12 ++++++++++-- 6 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 src/index.d.ts delete mode 100644 src/index.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 854bf6f..80d12ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,13 +11,16 @@ jobs: - name: Build the package run: | npm install - npm run build + LIB_ENTRY=components npm run build + LIB_ENTRY=utils npm run build + LIB_ENTRY=theme npm run build + cp src/index.d.ts dist/ - name: Prepare files for archiving env: - FILES: package.json package-lock.json dist + FILES: package.json package-lock.json run: | - mkdir luminar - cp -r $FILES luminar + cp -r $FILES dist + mv dist luminar - name: Archive the built package uses: TheDoctor0/zip-release@0.7.6 with: diff --git a/package.json b/package.json index 6931e97..f8b905b 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,7 @@ "private": true, "version": "0.0.3", "type": "module", - "main": "dist/index.js", - "types": "dist/index.d.ts", + "types": "index.d.ts", "scripts": { "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "build": "tsc && vite build", diff --git a/src/components/index.ts b/src/components/index.ts index 3161154..0e3ec2f 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1,3 +1,5 @@ +import "../globals.css"; + export * from "./Card"; export * from "./FixedBanner"; export * from "./FormButton"; diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..c614433 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,3 @@ +export * as components from "./components"; +export * as theme from "./theme"; +export * as utils from "./utils"; diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 9d00cdb..0000000 --- a/src/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import "./globals.css"; - -export * from "./components"; -export * as theme from "./theme"; -export * from "./utils"; diff --git a/vite.config.ts b/vite.config.ts index 2b9ab64..5a16082 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,13 +4,21 @@ import { defineConfig } from "vite"; import dts from "vite-plugin-dts"; import { libInjectCss } from "vite-plugin-lib-inject-css"; +const entries = ["components", "utils", "theme"]; +const entry = process.env.LIB_ENTRY || entries[0]; + +if (!entries.includes(entry)) { + throw new Error(`'${entry}' is not a valid entry`); +} + // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react(), libInjectCss(), dts()], + plugins: [react(), libInjectCss(), dts({ entryRoot: `src/${entry}` })], build: { copyPublicDir: false, + outDir: `dist/${entry}`, lib: { - entry: resolve(__dirname, "src/index.ts"), + entry: resolve(__dirname, `src/${entry}/index.ts`), fileName: "index", formats: ["es"], },