esgleam
Types
Config for esbuild
pub type Config {
Config(
outdir: String,
entry_points: List(String),
format: Format,
kind: Kind,
minify: Bool,
target: List(String),
serve: Option(String),
sourcemap: Bool,
watch: Bool,
raw: String,
)
}
Constructors
-
Config( outdir: String, entry_points: List(String), format: Format, kind: Kind, minify: Bool, target: List(String), serve: Option(String), sourcemap: Bool, watch: Bool, raw: String, )
Arguments
-
outdir
Output directory
-
entry_points
List of entry points supplied
-
format
Output format for JavaScript. See
Format
defaultEsm
-
kind
Kind for output
defaultLibrary
-
minify
default
False
-
target
List of target environments
default[]
-
serve
The root directory for the dev server (run server when defined)
defaultNone
-
sourcemap
Generate sourcemap for JavaScript
defaultFalse
-
watch
Enable watchmode. Bundles files on change
Note:gleam build
need to be run manually
defaultFalse
-
raw
raw flags to pass to esbuild
default""
-
Output format of generated JavaScript
pub type Format {
Esm
Cjs
Iife
}
Constructors
-
Esm
ECMAScript module
-
Cjs
CommonJS
-
Iife
immediately-invoked function expression
Functions
pub fn bundle(config: Config) -> Result(Nil, FileError)
Executes esbuild
with the provided config parsed as CLI arguments.
pub fn entry(config: Config, path: String) -> Config
Entry points
Can be use multiple times
pub fn kind(config: Config, kind: Kind) -> Config
Kind for output. see Kind
if set to Script
, will ignore all entries except the first and will call its main
function.
pub fn new(outdir path: String) -> Config
Start to create a build script
> esbuild.new("./dist/static")
Config("./dist/static", ...)
pub fn serve(config: Config, dir path: String) -> Config
Start a development server on http://127.0.0.1:8000 with path
being /
pub fn target(config: Config, target: String) -> Config
Target for transpiled JavaScript. Can be used mutiple times
> esbuild.new("./dist/static")
> |> esbuild.target("es2020")
> |> esbuild.target("firefox110")
> |> esbuild.target("edge90")
pub fn watch(config: Config, do_watch: Bool) -> Config
Note: There is no file watcher for Gleam files so you have to manually run gleam build
on change.
pub fn watch_gleam() -> fn() -> Nil