Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
138 lines (99 sloc) 3.65 KB

Extended compiler options

This section is only for people who want roll their own build system instead of using the recommended build system: [BuckleScript build system: bsb], in general, it is safe to skip this section. It also adds some tips for people who debug the compiler.

BuckleScript inherits the command line arguments of the OCaml compiler. It also adds several flags:

-bs-main (single directory build)

bsc.exe -bs-main Main

bsc.exe will build module Main and all its dependencies and when it finishes, it will run node main.js.

bsc.exe -c -bs-main Main

The same as above, but will not run node.


So that you can do

bsc.exe -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.


The project name of your project. The user is suggested to make it consistent with the name field in package.json


The format is module_system:oupt/path/relative/to/package.json Currently supported module systesms are: commonjs, amdjs and es6.

For example, when you want to use the es6 module system, you can do things like this:

bsc.exe -bs-package-name your_package -bs-package-output es6:lib/es6 -c
The user can supply multiple -bs-package-output at the same time.

For example:

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

It will 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 while google closure compiler supports all.


Turn off warnings on FFI type declarations.


bsc.exe -dparsetree -drawlambda -bs-eval 'Js.log "hello"'
[ (1)
  structure_item (//toplevel//[1,0+0]..[1,0+14])
    expression (//toplevel//[1,0+0]..[1,0+14])
      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 (js_dump "hello") (makeblock 0)))
'use strict';


/*  Not a pure module */
  1. Output by flag -dparsetree

  2. Output by flag -drawlambda

For this flag, it will not create any intermediate file, which is useful for learning or troubleshooting.

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

If the user doesn’t use any bs specific annotations, the user can explicitly turn it off. Another use case is that users can use -ppx explicitly as below:

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


Don’t print version header.