A smarter babel-cli


Keywords
cli, babel, javascript
License
MIT
Install
npm install sb-babel-cli@0.0.1

Documentation

SB-Babel-CLI

A smarter babel-cli. Supports caching and removing extra files from output directories.

Also supports running apps like nodemon, with --execute/-x, --execute-delay

Note: For Babel 6, see 0.1.x branch

Note: For v3, see v3 branch

Installation

npm install --save-dev sb-babel-cli
# OR Use with npx directory:
npx sb-babel-cli [options] <source directory>

Usage

Usage: sb-babel-cli [options] <source directory>

A smarter babel-cli

Options:
  -V, --version                        output the version number
  -w, --watch                          Watch files for changes
  --root <directory>                   Root directory for compilation; where presets and CLI config is resolved from (defaults to cwd)
  --cache-directory <directory>        Directory to store the cache ".sb-babel-cli" (defaults to homedir)
  --ignored <glob>                     Ignored files and directories that match the given glob (You can specify --ignored <glob> multiple times)
  --ignored-for-restart <glob>         These files are transpiled, but do not cause restart (You can specify --ignored-for-restart <glob> multiple times)
  --source-maps [true|false|inline]    Generate source maps for transpiled files
  --reset-cache                        Re-transpile all files ignoring cache
  --keep-extra-files                   Do NOT delete extra files in the output directory
  -o, --output-directory <directory>   Output directory to write transpiled files to
  --output-file-extension <extension>  Output file extension (defaults to .js)
  -x, --execute <entryFile>            Relative path of file to execute (only supported in watcher mode)
  --execute-delay <delay>              Delay in ms in between restarts of executed file (defaults to 1000ms)
  --extensions <exts>                  Comma separated extensions to process through the CLI (defaults to .js)
  --no-load-config                     Disables loading of "sb-config-file" from package.json (in --root)
  --print-config                       Print the config being used (for debugging only)
  --silent                             Disable log outputs
  --debug-port <arg>                   Passthrough arg for Node.js runtime for programs executed through -x
  --inspect-port <arg>                 Passthrough arg for Node.js runtime for programs executed through -x
  --inspect                            Passthrough arg for Node.js runtime for programs executed through -x
  --inspect-brk                        Passthrough arg for Node.js runtime for programs executed through -x
  --inspect-publish-uid <arg>          Passthrough arg for Node.js runtime for programs executed through -x
  --enable-source-maps                 Passthrough arg for Node.js runtime for programs executed through -x
  -h, --help                           display help for command

Arguments after -- will be passed as-are to programs executed through -x

Configuration

In addition to specifying options in CLI, you can also add them to your package.jsons (located through --root or cwd) with the key sb-babel-cli. Here are the supported options

interface Config {
  outputDirectory: string
  cacheDirectory: string

  outputFileExtension: string
  watch: boolean
  ignored: string[]
  ignoredForRestart: string[]
  sourceMaps: boolean | 'inline'
  resetCache: boolean
  keepExtraFiles: boolean
  execute: string
  executeDelay: number
  extensions: string[]
  printConfig: boolean
  silent: boolean
  nodeArgs: string[]
  programArgs: string[]
}

For example, for Typescript you can use the following configuration

// package.json
{
  "name": "...",
  // ...
  "sb-babel-cli": {
    "extensions": [".js", ".ts", ".tsx"]
  }
}

Examples

# To compile contents of src to lib directory
$ sb-babel-cli src -o lib
# To compile contents of src to lib directory and execute lib/server
$ sb-babel-cli src -o lib -x lib/server

License

This project is licensed under the terms of the MIT License. See the LICENSE file for more info.