diff --git a/bun.lockb b/bun.lockb index 706c685..6265477 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index bf0f614..618958d 100644 --- a/package.json +++ b/package.json @@ -112,5 +112,8 @@ }, "peerDependencies": { "typescript": "^5.0.0" + }, + "dependencies": { + "crypto-browserify": "^3.12.0" } } diff --git a/tsup.config.ts b/tsup.config.ts index 51d24f7..232d735 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,14 +1,30 @@ -import { defineConfig } from 'tsup'; +import { defineConfig } from "tsup"; export default defineConfig({ - entry: ['./src/index.ts'], - tsconfig: './tsconfig.json', + entry: ["./src/index.ts"], + tsconfig: "./tsconfig.json", splitting: false, - format: ['cjs', 'esm'], + format: ["cjs", "esm"], minify: true, clean: true, sourcemap: true, dts: true, - publicDir: './dist', - external: ['node:crypto'], + publicDir: "./dist", + external: ["node:crypto"], + esbuildOptions(options) { + options.plugins = [ + { + name: "replace-node-crypto", + setup(build) { + build.onResolve({ filter: /^node:crypto$/ }, (args) => { + if (build.initialOptions.platform === "browser") { + return { path: require.resolve("crypto-browserify") }; + } else { + return { path: "crypto" }; + } + }); + }, + }, + ]; + }, });