0.11.1 ā€¢ Published 25 days ago

melodist v0.11.1

Weekly downloads
-
License
MIT
Repository
-
Last release
25 days ago

šŸ“¦ melodist

An opinionated bundler for creating TypeScript libraries.

šŸ”— Installation

With NPM:

npm install -D melodist

With Yarn:

yarn add -D melodist

šŸ“– Documentation

Making sense of melodist outputs

melodist works in tandem with ESBuild and TypeScript to generate production-ready code bundles that are publishable to NPM, along with TypeScript definition files to support strongly-typed integrations by default.

A typical output looks like this:

your_project/
ā””ā”€ā”€ .melodist/
    ā”‚
    ā”‚   # CommonJS modules (with --format=cjs)
    ā”œā”€ā”€ cjs/
    ā”‚   ā”œā”€ā”€ index.js
    ā”‚   ā”œā”€ā”€ index.js.map
    ā”‚   ā”œā”€ā”€ [index.css]
    ā”‚   ā””ā”€ā”€ [index.css.map]
    ā”‚
    ā”‚   # ES modules (with --format=esm)
    ā”œā”€ā”€ esm/
    ā”‚   ā”œā”€ā”€ index.js
    ā”‚   ā”œā”€ā”€ index.js.map
    ā”‚   ā”œā”€ā”€ index.mjs
    ā”‚   ā”œā”€ā”€ index.mjs.map
    ā”‚   ā”œā”€ā”€ [index.css]
    ā”‚   ā””ā”€ā”€ [index.css.map]
    ā”‚
    ā”‚   # Immediately-invoked function expression (with --format=iife)
    ā”œā”€ā”€ iife/
    ā”‚   ā”œā”€ā”€ index.js
    ā”‚   ā”œā”€ā”€ index.js.map
    ā”‚   ā”œā”€ā”€ [index.css]
    ā”‚   ā””ā”€ā”€ [index.css.map]
    ā”‚
    ā”‚   # React Native modules (with --format=rn)
    ā”œā”€ā”€ rn/
    ā”‚   ā”œā”€ā”€ index.js
    ā”‚   ā””ā”€ā”€ index.js.map
    ā”‚
    ā”‚   # TypeScript definitions
    ā””ā”€ā”€ types/
        ā””ā”€ā”€ *.d.ts

melodist generates multiple outputs in order to maximize backwards compatibility and interoperability across JS runtimes. These outputs can be associated with entrypoints configured in package.json:

{
  // CommonJS output
  "main": "./.melodist/cjs/index.js",

  // ES modules output (legacy)
  "module": "./.melodist/esm/index.js",

  // TypeScript definition
  "types": "./.melodist/types/index.d.ts",

  // React Native output
  "react-native": "./.melodist/rn/index.js",

  // CDN entrypoint
  "jsdelivr": "./.melodist/iife/index.js",

  // You should also define a standard NodeJS
  // "exports" field, for maximum compatibility
  "exports": {
    // ES modules output (using `.mjs` extension)
    "import": "./.melodist/esm/index.mjs",
    // CommonJS output (for redundancy)
    // (this should remain in-sync with package.json#main)
    "require": "./.melodist/cjs/index.js"
  }
}

Entrypoints

By default, [srcdir]/index.{ext} is resolved as a starting point for bundling. Values for {ext} can be one of:

  • TypeScript: ts or tsx
  • JavaScript: js or jsx
  • CSS: css

A JavaScript and/or TypeScript entry-point is required for each bundle. CSS is optional.

If [srcdir] isn't found, or if an entry-point fails to resolve relative to [srcdir], then index.{ext} will be resolved at the project root relative to your package.json.

For greater flexibility, each delivery format (CommonJS modules, ES modules, IIFE modules, and React Native) can define its own entrypoint using a filename identifier.

  • CommonJS: index.cjs.{ext}
  • ES: index.esm.{ext}
  • IIFE: index.iife.{ext}
  • React Native: index.rn.{ext}

Defining external dependencies

By default, "dependencies" and "peerDependencies" listed in package.json are marked "external" ā€” meaning those dependencies won't be included in the bundle, only referenced by the relevant module system (import or require). These defaults can be extended through the use of --external flags.

For IIFE bundles, externals can be defined separately using --external:iife flags, falling back to "dependencies", "peerDependencies" and --external where necessary.

Defining global Dependencies

Global dependencies can defined through the use of --global flags. Dependencies marked as global are compiled to a variable reference on a global object. This is handy for situations where external dependencies may be included via <script> tags in a browser.

For IIFE bundles, globals can be defined separately using --global:iife flags, falling back to --global where necessary.

Commands

melodist build / melodist dev

melodist build creates an optimized, production-ready bundle.

melodist dev serves a hot-reloading development server.

Both commands accept the same positional arguments and flags:

USAGE

$ melodist <build|dev> [options] [<srcdir>]

ARGUMENTS

srcdir   Directory where input shall be consumed from. Default: "./src"

OPTIONS

--outdir, -o       Directory where output shall be placed. Default: ".melodist"

--outdir:iife,     Directory where output shall be placed if --format=iife is in
-o:iife            use. Default: falls back to --outdir

--outdir:cjs,      Directory where output shall be placed if --format=cjs is in use.
-o:cjs             Default: falls back to --outdir

--outdir:esm,      Directory where output shall be placed if --format=esm is in use.
-o:esm             Default: falls back to --outdir

--outdir:rn,       Directory where output shall be placed if --format=rn is in use.
-o:rn              Default: falls back to --outdir

--outdir:types,    Directory where generated type definitions shall be placed.
-o:types           Default: falls back to --outdir

--format, -f       A list of output formats that should be produced. Default:
                   ["cjs", "esm"]

--es-target        The EcmaScript syntax version to compile to. Default: "esnext"

--platform, -p     Target platform (one of: browser, node, neutral). Default:
                   "neutral"

--external, -e     Dependencies to be externalized. Default: inferred from
                   `dependencies` and `peerDependencies`

--external:iife,   Dependencies to be externalized if --format=iife is in use.
-e:iife            Default: falls back to --external

--global, -g       Dependencies transpiled to global variables (i.e.: --global
                   react=React).

--global:iife,     Dependencies transpiled to global variables if --format=iife is
-g:iife            in use (i.e.: --global:iife react=React). Default: falls back to
                   --global

--name             A global variable name to use if --format=iife is in use.

--(no-)sourcemap   Generate sourcemaps. Default: true

--env              ENV file from which to load environment data.

--tsconfig         TSConfig file from which to load TypeScript configuration.
                   Default: "tsconfig.json"

--(no-)typecheck   Whether to validate TypeScript typings at build time. Default:
                   true

--(no-)minify      Whether to optimize bundles through code minification. Default:
                   true

--help, -h         Show help text (you're lookin' at it).

--version, -v      Show current version.
0.11.1

25 days ago

0.11.0

9 months ago

0.10.1

1 year ago

0.10.2

1 year ago

0.10.3

1 year ago

0.10.4

1 year ago

0.10.5

1 year ago

0.10.0

1 year ago

0.8.5

1 year ago

0.8.4

1 year ago

0.9.0

1 year ago

0.8.1

1 year ago

0.8.0

1 year ago

0.8.3

1 year ago

0.8.2

1 year ago

0.7.9

2 years ago

0.7.8

2 years ago

0.7.7

2 years ago

0.7.6

2 years ago

0.7.5

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.2

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago