Skip to content

Commit

Permalink
feat: add CommonJS support
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
jerome-benoit committed Oct 8, 2024
1 parent a864d19 commit 8825565
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- Support for sync and async benchmark ✔
- Advanced benchmark statistics: significance, error margin, variance, standard deviation, p-quantiles, ... ✔
- Multiple JS runtime support at zero cost abstraction (primary support for node, deno, bun and browsers but works with all JS runtime) ✔
- Support for ESM and TypeScript ✔
- Support for CommonJS, ESM and TypeScript ✔

## Table of contents

Expand Down
16 changes: 16 additions & 0 deletions bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const entryPoints = ['./src/index.js']

export const baseBuildDir = './dist'
export const browserBuildDir = `${baseBuildDir}/browser`
export const commonJsBuildDir = `${baseBuildDir}/cjs`

console.time('Browser build time')
if (existsSync(browserBuildDir)) {
Expand All @@ -19,3 +20,18 @@ await build({
sourcemap: 'external',
})
console.timeEnd('Browser build time')

console.time('CommonJS build time')
if (existsSync(commonJsBuildDir)) {
rmSync(commonJsBuildDir, { recursive: true })
}

await build({
entrypoints: entryPoints,
outdir: commonJsBuildDir,
target: 'node',
format: 'cjs',
minify: true,
sourcemap: 'external',
})
console.timeEnd('CommonJS build time')
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
"type": "module",
"license": "MIT",
"version": "0.8.2",
"packageManager": "[email protected].29",
"packageManager": "[email protected].30",
"bin": {
"tatami": "cli.js"
},
"types": "./src/index.d.ts",
"main": "./src/index.js",
"main": "./dist/cjs/index.js",
"module": "./src/index.js",
"browser": "./dist/browser/index.js",
"exports": {
"types": "./src/index.d.ts",
"require": "./dist/cjs/index.js",
"import": "./src/index.js",
"browser": "./dist/browser/index.js"
},
Expand Down

0 comments on commit 8825565

Please sign in to comment.