cosmic-esbuild
Simplifying esbuild configurations in a familiar way.

Description
This package allows you to declaratively configure esbuild
using the popular cosmiconfig
format. No more custom build scripts, no more lengthy build commands in your manifest.
Installation
npm install cosmic-esbuild
Usage
Configuration
Create a file for your configuration, see the following examples:
JSON
{
"bundle": true,
"entryPoints": ["app.js"],
"outdir": "lib",
"sourcemap": "external"
}
YAML
bundle: true
entryPoints:
- "app.js"
outdir: "lib"
sourcemap: "external"
TOML
bundle = true
entryPoints = [ "app.js" ]
outdir = "lib"
sourcemap = "external"
TypeScript
import type { BuildOptions } from "esbuild";
const config = {
bundle: true,
entryPoints: ["app.js"],
outdir: "dist",
sourcemap: "external",
} satisfies BuildOptions;
export default config;
package.json
This is an extended example that also includes possible scripts
{
"name": "your-package",
"scripts": {
"build": "cosmic-esbuild",
"dev": "cosmic-esbuild --watch"
},
"esbuild": {
"bundle": true,
"entryPoints": ["app.js"],
"outdir": "lib",
"sourcemap": "external"
}
}
Supported formats
You can write your configuration to any of the following formats (sorted by precedence):
package.json
(add the esbuild
property with your config)
.esbuildrc
(JSON or YAML)
.esbuildrc.json
.esbuildrc.jsonc
.esbuildrc.yaml
.esbuildrc.yml
.esbuildrc.toml
esbuild.config.json
esbuild.config.jsonc
esbuild.config.yaml
esbuild.config.yml
esbuild.config.toml
esbuild.config.js
esbuild.config.ts
esbuild.config.cjs
esbuild.config.mjs
CLI
npx cosmic-esbuild
npx cosmic-esbuild --config esbuild.config.ts
npx cosmic-esbuild --watch
[!NOTE]
The CLI should primarily be used with configuration files. However, some of the basic esbuild options can be passed as command-line arguments. It's not a goal of this project to replicate esbuild's CLI functionality.
For a full list of command-line arguments, run npx cosmic-build --help
.
License
This work is licensed under The MIT License.