-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1192f3
commit 089b503
Showing
57 changed files
with
3,705 additions
and
626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env zx | ||
/* eslint-disable no-undef */ | ||
import "zx/globals"; | ||
|
||
import * as esbuild from "esbuild"; | ||
|
||
const config = { | ||
entryPoints: ["src/**/*"], | ||
minify: true, | ||
bundle: false, | ||
treeShaking: true, | ||
sourcemap: true, | ||
color: true, | ||
loader: { | ||
".json": "copy", | ||
}, | ||
}; | ||
|
||
const buildEsm = async () => { | ||
console.log(chalk.blue("Building esm...")); | ||
await esbuild.build({ | ||
...config, | ||
outdir: "lib/esm", | ||
format: "esm", | ||
platform: "browser", | ||
plugins: [ | ||
{ | ||
name: "copy-package-json", | ||
setup(build) { | ||
build.onEnd(async () => { | ||
await $`cp package.json lib/esm/package.json`; | ||
}); | ||
}, | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
const buildCjs = async () => { | ||
console.log(chalk.blue("Building cjs...")); | ||
await esbuild.build({ | ||
...config, | ||
outdir: "lib/cjs", | ||
format: "cjs", | ||
platform: "node", | ||
plugins: [ | ||
{ | ||
name: "copy-package-json", | ||
setup(build) { | ||
build.onEnd(async () => { | ||
await $`cp package.json lib/cjs/package.json`; | ||
}); | ||
}, | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
const buildTypes = async dir => { | ||
console.log(chalk.blue("Building types...")); | ||
await $`tsc --emitDeclarationOnly --outDir ${dir} --moduleResolution bundler -m esnext`; | ||
}; | ||
|
||
const main = async () => { | ||
return Promise.all([buildEsm(), buildCjs(), buildTypes("lib/types")]); | ||
}; | ||
|
||
main().catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env zx | ||
/* eslint-disable no-undef */ | ||
import "zx/globals"; | ||
|
||
import * as esbuild from "esbuild"; | ||
|
||
const { platform } = argv; | ||
|
||
const config = { | ||
entryPoints: ["src/**/*"], | ||
minify: true, | ||
bundle: false, | ||
treeShaking: true, | ||
sourcemap: true, | ||
color: true, | ||
loader: { | ||
".json": "copy", | ||
}, | ||
}; | ||
|
||
const getEsmContext = async () => { | ||
console.log(chalk.blue("Getting esm context...")); | ||
|
||
return esbuild.context({ | ||
...config, | ||
outdir: "lib/esm", | ||
format: "esm", | ||
platform: "browser", | ||
plugins: [ | ||
{ | ||
name: "copy-package-json", | ||
setup(build) { | ||
build.onEnd(async () => { | ||
await $`cp package.json lib/esm/package.json`; | ||
}); | ||
}, | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
const getCjsContext = async () => { | ||
console.log(chalk.blue("Getting cjs context...")); | ||
|
||
return esbuild.context({ | ||
...config, | ||
outdir: "lib/cjs", | ||
format: "cjs", | ||
platform: "node", | ||
plugins: [ | ||
{ | ||
name: "copy-package-json", | ||
setup(build) { | ||
build.onEnd(async () => { | ||
await $`cp package.json lib/cjs/package.json`; | ||
}); | ||
}, | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
const watchTypes = async () => { | ||
await $`tsc --watch --emitDeclarationOnly --outDir lib/types --moduleResolution bundler -m esnext`; | ||
}; | ||
|
||
const watch = async () => { | ||
const esmContext = await getEsmContext(); | ||
const cjsContext = await getCjsContext(); | ||
|
||
if (platform === "esm") { | ||
console.log(chalk.blue("Watching esm...")); | ||
await Promise.all([esmContext.watch(), watchTypes()]); | ||
} else if (platform === "cjs") { | ||
console.log(chalk.blue("Watching cjs...")); | ||
await Promise.all([cjsContext.watch(), watchTypes()]); | ||
} else { | ||
console.log(chalk.blue("Watching all...")); | ||
await Promise.all([esmContext.watch(), cjsContext.watch(), watchTypes()]); | ||
} | ||
}; | ||
|
||
watch().catch(error => { | ||
console.error(error); | ||
process.exitCode = error?.exitCode ?? 1; | ||
}); |
Oops, something went wrong.