Skip to content

Commit

Permalink
Merge pull request #8 from okikio:okikio/bug-using-script-type-module-7
Browse files Browse the repository at this point in the history
fix: add back support for umd #7
  • Loading branch information
okikio authored Feb 1, 2024
2 parents f2a06c0 + 3f1a376 commit 817dc23
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"access": "public",
"legacy": "lib/index.cjs",
"main": "lib/index.cjs",
"browser": "lib/index.js",
"browser": "lib/index.umd.js",
"module": "lib/index.js",
"exports": {
".": {
Expand Down Expand Up @@ -119,6 +119,7 @@
"@types/node": "^20.10.4",
"@types/web": "^0.0.127",
"esbuild": "^0.19.9",
"esbuild-plugin-umd-wrapper": "^2.0.0",
"husky": "^8.0.3",
"pnpm": "^8.12.0",
"semantic-release": "^22.0.12",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 28 additions & 2 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
import type { Options } from 'tsup';
import { defineConfig } from 'tsup';
import { umdWrapper } from 'esbuild-plugin-umd-wrapper';

export default defineConfig({
import { umd } from "./package.json";

const GLOBAL_NAME = umd;

const baseConfig: Options = {
target: ["es2022", "node21", "chrome105"],
entry: ['src/index.ts'],
format: ["esm", "cjs"],
sourcemap: true,
clean: true,
dts: true,
outDir: "lib",
})
platform: 'browser',
globalName: GLOBAL_NAME,

outExtension({ format, options }) {
const ext = ({ "esm": "js", "cjs": "cjs", "umd": "umd.js" })[format]
const outputExtension = options.minify ? `min.${ext}` : `${ext}`
return {
js: `.${outputExtension}`,
}
},
}

export default defineConfig([
{ ...baseConfig },
{
...baseConfig,
target: 'es5',
format: ['umd'],
esbuildPlugins: [umdWrapper({ libraryName: GLOBAL_NAME, external: 'inherit' })],
},
])

0 comments on commit 817dc23

Please sign in to comment.