官术网_书友最值得收藏!

Setting up a pure Reason project

The bsb binary includes a project generator. We'll use it to create a pure Reason project using the basic-reason theme. Run bsb -themes to see all available project templates:

Available themes: 
basic
basic-reason
generator
minimal
node
react
react-lite
tea

Since BuckleScript works with both OCaml and Reason, some themes are only for OCaml projects. That being said, feel free to mix OCaml's .ml files with Reason's .re files within any BuckleScript project.

In this chapter, we'll focus on using the basic-reason and react templates. If you're curious, the react-lite theme is like the react one, except webpack is replaced with a simpler, faster, and more reliable module bundler that is intended only for development purposes.

Let's first create a pure Reason project:

bsb -init my-first-app -theme basic-reason
cd my-first-app

When we open the project in our editor, we see the following project structure:

├── .gitignore
├── README.md
├── bsconfig.json
├── node_modules
│ ├── .bin
│ │ ├── bsb
│ │ ├── bsc
│ │ └── bsrefmt
│ └── bs-platform
├── package.json
└── src
└── Demo.re

Overall, there isn't much here, which is kind of refreshing coming from JavaScript. In node_modules, we see bs-platform along with some binaries:

  • bsb: The build system
  • bsc: The compiler
  • bsrefmt: This is essentially JavaScript's prettier, but for Reason

As we'll soon see, the bsb binary is used within npm scripts. This bsc binary is rarely used directly. The bsrefmt binary is used by editor plugins.

In Demo.re, we see a simple log message:

/* Demo.re */
Js.log("Hello, BuckleScript and Reason!");

package.json looks somewhat familiar. The scripts field shows our currently available npm scripts:

/* package.json */
{
"name": "my-first-app",
"version": "0.1.0",
"scripts": {
"build": "bsb -make-world",
"start": "bsb -make-world -w",
"clean": "bsb -clean-world"
},
"keywords": [
"BuckleScript"
],
"author": "",
"license": "MIT",
"devDependencies": {
"bs-platform": "^4.0.5"
}
}

Run npm run build to compile Demo.re to JavaScript. By default, the compiled output appears right beside the source file as Demo.bs.js. How does it know which files to compile, and where to output them? That's where bsconfig.json comes in.

主站蜘蛛池模板: 保德县| 穆棱市| 根河市| 漳平市| 夏邑县| 佛坪县| 睢宁县| 松阳县| 耿马| 林芝县| 黔西| 织金县| 西安市| 枣阳市| 临颍县| 万源市| 清流县| 台东市| 咸宁市| 长汀县| 洛川县| 无棣县| 德惠市| 韩城市| 响水县| 上杭县| 巴南区| 崇礼县| 海伦市| 常熟市| 新干县| 西昌市| 托里县| 安新县| 寿阳县| 常州市| 巴林左旗| 蒲城县| 亚东县| 团风县| 丰县|