From 701e82300b813aaa84e270d291ae08d4c053de94 Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sat, 20 Jul 2024 11:18:01 +0900 Subject: [PATCH] build: Add build for browsers --- .gitignore | 1 + package.json | 1 + src/browser.ts | 8 ++++++++ tsup.config.ts | 25 ++++++++++++++++++------- 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/browser.ts diff --git a/.gitignore b/.gitignore index 046a8d30..6f91fbb6 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ dist out *.d.ts *.tgz +umd \ No newline at end of file diff --git a/package.json b/package.json index 5eda852a..497b8671 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", + "browser": "./umd/browser.global.js", "exports": { ".": { "import": { diff --git a/src/browser.ts b/src/browser.ts new file mode 100644 index 00000000..6671ab0b --- /dev/null +++ b/src/browser.ts @@ -0,0 +1,8 @@ +import * as toolkit from './index'; + +interface Window { + _: typeof toolkit; +} + +declare var window: Window; +window._ = toolkit; diff --git a/tsup.config.ts b/tsup.config.ts index b77c30cc..68247437 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,9 +1,20 @@ import { defineConfig } from 'tsup'; -export default defineConfig({ - format: ['cjs', 'esm'], - entry: ['src/*.ts', 'src/*/*.ts', '!**/*.{spec,test,test-d}.*'], - sourcemap: true, - dts: true, - clean: true, -}); +export default [ + defineConfig({ + format: ['cjs', 'esm'], + entry: ['src/*.ts', 'src/*/*.ts', '!**/*.{spec,test,test-d}.*'], + sourcemap: true, + dts: true, + clean: true, + }), + defineConfig({ + format: ['iife'], + outDir: 'umd', + entry: ['src/browser.ts'], + sourcemap: true, + dts: false, + clean: true, + minify: true, + }), +];