BuckleScript

BuckleScript

  • Docs
  • Try
  • API
  • Community
  • Blog
  • Languages icon中文
    • 日本語
    • English
    • Español
    • Français
    • 한국어
    • Português (Brasil)
    • Русский
    • 繁體中文
    • 帮助我们翻译
  • GitHub

›Advanced

Intro

  • What & Why
  • Installation
  • New Project
  • Concepts Overview

Interop

  • Overview
  • Cheatsheet
  • Embed Raw JavaScript
  • Common Data Types
  • Intro to External
  • Bind to Global Values
  • Null, Undefined & Option
  • Object
  • Object 2
  • Class
  • Function
  • Import & Export
  • Regular Expression
  • Exceptions
  • JSON
  • Fast Pipe
  • Generate Converters & Helpers
  • Better Data Structures Printing (Debug Mode)
  • NodeJS Special Variables
  • Miscellaneous
  • Browser Support & Polyfills

Build System

  • Overview
  • Configuration
  • Automatic Interface Generation
  • Interop with JS Build System
  • Performance
  • Advanced

Standard Library

  • Overview

Advanced

  • Conditional Compilation
  • Extended Compiler Options
  • Use Existing OCaml Libraries
  • Difference from Native OCaml
  • Compiler Architecture & Principles
  • Comparison to Js_of_ocaml
Translate

Extended Compiler Options

Note: this section is only for people who want roll their own build system instead of using the recommended build system, bsb. This also provides some tips for contributors who debug the compiler.

BuckleScript inherits the command line arguments of the OCaml compiler. It also adds several BS-specific flags. Run bsc -help to see the list.

All these flags can be passed into the bsc-flags section of bsb (though some of them don't make sense to be passed).

Note also that this section isn't kept very up-to-date. Contributions welcome!

-bs-main (single directory build)

bsc -bs-main Main

bsc will build module Main and all its dependencies. When it finishes, it'll run node main.js.

bsc -c -bs-main Main

Same as above, but will not run node.

-bs-files

So that you can do

bsc -c -bs-files *.ml *.mli

the compiler will sort the order of input files before starting compilation.

BuckleScript supports two compilation modes: script mode and package mode. In package mode, you have to provide package.json on top and set the options -bs-package-name, -bs-package-output. In script mode, such flags are not needed.

-bs-package-name

The name of your project. It's recommended to use the same name than the one in package.json.

-bs-packge-output

Configure the output module system. The format is module_system:output/path/relative/to/package.json.

Currently supported systesms are: commonjs, amdjs and es6.

For example, when you want to use the es6 module system:

bsc -bs-package-name your_package -bs-package-output es6:lib/es6 -c xx.ml

Note: you can supply multiple -bs-package-output at once. For example:

bsc -bs-package-name name -bs-package-output commonjs:lib/js  -bs-package-output amdjs:lib/amdjs -c x.ml

It'll generate x.js in lib/js as a commonjs module, lib/amdjs as an amdjs module at the same time.

You would then need a bundler for the different module systems: webpack supports commonjs and amdjs, rollup supports es6, while google closure compiler supports all.

-bs-no-warn-ffi-type

Turn off warnings on FFI type declarations.

-bs-eval

Example:

> bsc -dparsetree -drawlambda -bs-eval 'Js.log "hello"'

[
  structure_item (//toplevel//[1,0+0]..[1,0+14])
    Pstr_eval
    expression (//toplevel//[1,0+0]..[1,0+14])
      Pexp_apply
      expression (//toplevel//[1,0+0]..[1,0+6])
        Pexp_ident "Js.log" (//toplevel//[1,0+0]..[1,0+6])
      [
        <label> ""
          expression (//toplevel//[1,0+7]..[1,0+14])
            Pexp_constant Const_string("hello",None)
      ]
]

(setglobal Bs_internal_eval! (seq (log "hello") (makeblock 0)))
// Generated by BUCKLESCRIPT VERSION 2.1.0, PLEASE EDIT WITH CARE
'use strict';


console.log("hello");

/*  Not a pure module */

In conjunction with -bs-eval: the first block is the output of -dparsetree, the second is from -drawlambda.

-bs-eval doesn't create intermediate file. Useful for learning or troubleshooting.

-bs-no-builtin-ppx-ml, -bs-no-builtin-ppx-mli

If you don't use any BS-specific annotations, you can explicitly turn it off. Another use-case is to use -ppx explicitly as below:

bsc -c -ppx bsppx.exe -bs-no-builtin-ppx-ml c.ml

-bs-no-version-header

Don’t print BS version at the beginning of each JS file.

-bs-g (Experimental, since @3.1.0)

See Better Data Structures Printing (Debug Mode).

← 上一页下一页 →
  • -bs-main (single directory build)
  • -bs-files
  • -bs-package-name
  • -bs-packge-output
  • -bs-no-warn-ffi-type
  • -bs-eval
  • -bs-no-builtin-ppx-ml, -bs-no-builtin-ppx-mli
  • -bs-no-version-header
  • -bs-g (Experimental, since @3.1.0)