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)
SHbsc -bs-main Main
bsc will build module Main and all its dependencies. When it finishes, it'll run node main.js.
SHbsc -c -bs-main Main
Same as above, but will not run node.
-bs-files
So that you can do
SHbsc -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-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-package-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:
SHbsc -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:
SHbsc -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:
SH> 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 -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:
SHbsc -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.