February 2019
Beginner to intermediate
180 pages
4h 4m
English
To import a node module, use [@bs.module]. The compiled output depends on the package-specs configuration used within bsconfig.json. We're using es6 as the module format.
[@bs.module] external leftPad: (string, int) => string = "left-pad";let result = leftPad("foo", 6);
This compiles to the following:
import * as LeftPad from "left-pad";var result = LeftPad("foo", 6);export { result ,}
Setting the module format to commonjs results in the following compiled output:
var LeftPad = require("left-pad");var result = LeftPad("foo", 6);exports.result = result;
When there is no string argument to [@bs.module], the default value is imported.
Read now
Unlock full access