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
      default Esm

    • kind

      Kind for output
      default Library

    • minify

      default False

    • target

      List of target environments
      default []

    • serve

      The root directory for the dev server (run server when defined)
      default None

    • sourcemap

      Generate sourcemap for JavaScript
      default False

    • watch

      Enable watchmode. Bundles files on change
      Note: gleam build need to be run manually
      default False

    • 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

Kind of output

pub type Kind {
  Script
  Library
}

Constructors

  • Script

    Executes the main() function in your entry point

  • Library

    Only exports the code

Functions

pub fn bundle(config: Config) -> Result(Nil, FileError)
pub fn entry(config: Config, path: String) -> Config

Entry points
Can be use multiple times

pub fn format(config: Config, format: Format) -> Config

Output format. see Format

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 minify(config: Config, do_minify: Bool) -> Config

Create minified JavaScript

pub fn new(outdir path: String) -> Config

Start to create a build script

> esbuild.new("./dist/static")
Config("./dist/static", ...)
pub fn raw(config: Config, args: String) -> Config

Raw CLI argument to pass to esbuild

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
Search Document