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.
ReScript 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
bsc -c -bs-main Main
Same as above, but will not run
So that you can do
bsc -c -bs-files *.ml *.mli
the compiler will sort the order of input files before starting compilation.
ReScript 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-output. In script mode, such flags are not needed.
The name of your project. It's recommended to use the same
name than the one in
Configure the output module system. The format is
Currently supported systesms are:
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
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
amdjs, rollup supports es6, while google closure compiler supports all.
Turn off warnings on FFI type declarations.
> 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 ReScript 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
-bs-eval doesn't create intermediate file. Useful for learning or troubleshooting.
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
Don’t print BS version at the beginning of each JS file.