Skip to content

Command line interface

Rich-Harris edited this page Nov 22, 2014 · 3 revisions

You can use Esperanto as a node.js module, or via the command line interface. To use the CLI, you must first install Esperanto globally:

npm install -g esperanto

This will give you access to the esperanto command.

For help, run esperanto -h or esperanto --help.

Basic options

-v, --version            Show version number
-h, --help               Show help message
-i, --input              Input file (if absent, reads from stdin)
-o, --output <output>    Output file (if absent, prints to stdout)
-t, --type [amd]         Type of output (amd, cjs, umd)
-s, --strict             Use strict mode
-b, --bundle             Create a bundle including <file>'s dependencies
-n, --name               Name for UMD export
-m, --sourcemap          Generate sourcemap (`-m inline` for inline map)

Additional options when bundling

-d, --basedir=<basedir>  Base directory for module resolution
-k, --skip=<files...>    Comma-separated list of files to skip (relative to basedir)

Examples

Transpiling a single module to AMD (default format)

esperanto -i src/input.js > output.js

Transpiling a single module to CommonJS

esperanto -i src/input.js -t cjs > output.js

Transpiling a single module to UMD

Note: You must supply a --name or -n option for the exported value.

esperanto -i src/input.js -t umd -n myModule > output.js

Using strict mode

esperanto -i src/input.js -s > output.js

Saving to a file in a folder that may not exist yet

esperanto -i src/input.js -o path/to/nonexistentdir/output.js

Adding a sourcemap

Note: You must specify --input (-i) and --output (-o) options rather than reading from stdin/writing to stdout.

# This will create an output.js.map file in addition to output.js
esperanto -i src/input.js -m -o output.js

# This will add the sourcemap as an inline data URI to output.js
esperanto -i src/input.js -m inline -o output.js

Bundling modules

esperanto -i src/input.js -b > output.js