From ee1ca36125af6414fa15242b35a20fb15fedfcaa Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Wed, 24 Jul 2024 13:10:00 +0200 Subject: [PATCH] improve treeshaking --- .size-limit.ts | 2 +- package.json | 10 ++++++++++ tsup.config.ts | 9 +++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.size-limit.ts b/.size-limit.ts index 6e08f51..831ac16 100644 --- a/.size-limit.ts +++ b/.size-limit.ts @@ -3,7 +3,7 @@ import { globbySync } from "globby"; import type { SizeLimitConfig } from "size-limit"; // Get all hooks from the `src/hooks` directory, and validate their size -const limits = globbySync("src/hooks/*.ts").map((file) => { +const limits = globbySync("src/hooks/use*.ts").map((file) => { const name = path.parse(file).name; return { diff --git a/package.json b/package.json index 19a7e75..355190a 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,16 @@ "types": "./dist/index.d.cts", "default": "./dist/index.cjs" } + }, + "./*": { + "import": { + "types": "./dist/hooks/*.d.ts", + "default": "./dist/hooks/*.js" + }, + "require": { + "types": "./dist/hooks/*.d.ts", + "default": "./dist/hooks/*.cjs" + } } }, "scripts": { diff --git a/tsup.config.ts b/tsup.config.ts index d08e0ae..3379d2a 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,14 +1,15 @@ +import { globbySync } from "globby"; import { defineConfig } from "tsup"; +const hooks = globbySync("src/hooks/use*.ts"); + export default defineConfig({ minify: false, - sourcemap: true, dts: true, clean: true, - target: "es2018", - external: ["react"], + external: ["react", "react-dom"], format: ["esm", "cjs"], - entry: ["src/index.ts"], + entry: ["src/index.ts", ...hooks], outDir: "dist", treeshake: true, });