ReasonML Quick Start Guide
上QQ阅读APP看书,第一时间看更新

The bsconfig.json file

The bsconfig.json file is a required file for all BuckleScript projects. Let's explore it:

// This is the configuration file used by BuckleScript's build system bsb. Its documentation lives here: http://bucklescript.github.io/bucklescript/docson/#build-schema.json
// BuckleScript comes with its own parser for bsconfig.json, which is normal JSON, with the extra support of comments and trailing commas.
{
"name": "my-first-app",
"version": "0.1.0",
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
// add your dependencies here. You'd usually install them normally through `npm install my-dependency`. If my-dependency has a bsconfig.json too, then everything will work seamlessly.
],
"warnings": {
"error" : "+101"
},
"namespace": true,
"refmt": 3
}

We'll soon be changing some of these defaults to get more comfortable with BuckleScript's configuration file. Let's first add the following code to Demo.re:

type decision =
| Yes
| No
| Maybe;

let decision = Maybe;

let response =
switch (decision) {
| Yes => "Yes!"
| No => "I'm afraid not."
};

Js.log(response);

As you can see, the switch expression isn't handling all possible cases of decisionRunning npm run build results in the following output:

ninja: Entering directory `lib/bs'
[3/3] Building src/Demo.mlast.d
[1/1] Building src/Demo-MyFirstApp.cmj

Warning number 8
.../Demo.re 9:3-12:3

7 │
8 │ let response =
9 │ switch (decision) {
10 │ | Yes => "Yes!"
11 │ | No => "I'm afraid not."
12 │ };
13 │
14 │ Js.log(response);

You forgot to handle a possible value here, for example:
Maybe