• This repository has been archived on 03/Dec/2018
  • Stars
    star
    628
  • Rank 71,541 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔰 Create a ReasonML and React development environment


Reason Scripts

  $ yarn create react-app my-app --scripts-version reason-scripts

Reason Scripts provides a JS-like development environment for developing web apps with the Reason programming language and React. It bootstraps an environment to automatically compile all Reason code to JS, provide features like reloading and bundling, and seamlessly use JS code from Reason.

Build Status Build status

Getting Started

Using Yarn

Note that using yarn create requires Yarn 0.25 or later

To create a new app using Reason and React, run:

$ npm install -g bs-platform
$ yarn create react-app <app-name> --scripts-version reason-scripts
$ cd <app-name>
$ yarn start

Make sure to install bs-platform globally using npm instead of yarn.

Using npm

$ npm install -g bs-platform
$ npx create-react-app <app-name> --scripts-version reason-scripts
$ cd <app-name>
$ npm start

(npx comes with npm 5.2+ and higher, see instructions for older npm versions)

The policy of reason tooling is to support the current LTS release, so please make sure you have Node 8 or later.

Directory Layout

Creating a new app makes an <app-name> directory with the following layout:

<app-name>/
  README.md
  node_modules/
  package.json
  bsconfig.json
  .gitignore
  public/
    favicon.ico
    index.html
  src/
    index.re
    index.css
    app.re
    app.css
    logo.svg

Features

Everything from Create React App

  • Highly-optimized build configuration
  • Pre-configured test runner
  • Friendly developer environment
  • "eject" Webpack config
  • Environment variable configuration
  • Automatic PWA configuration
  • Low configuration builds

Reason Entrypoint

The entry point to the app is src/index.re. From the start your new app will be based on Reason, but can seamlessly interop with existing JS files and projects!

Automatic Compilation of Reason/OCaml files

Any Reason/OCaml file will be automatically compiled to a JS file. For example, a file called math_fns.re can be required by a JS file:

import { add } from './math_fns.re'

const sum = add(1, 4)

Jest Integration

Reason Scripts will automatically configure a Jest environment to test Reason code. Any code found in a file ending with _test.re, _test.ml or test.js will be considered a test and run with Jest. From these files, the normal Jest API can be used interacting with any other modules defined in your app. For example:

/* math_fns.re */

let add = (x, y) => x + y;
/* math_fns_test.re */

open Jest;

test("addition", () => {
  let num_1 = 10;
  let num_2 = 12;

  expect(Math_fns.add num_1 num_2) |> toBe(22);
});

Or if you prefer writing your tests in JavaScript, just don't forget to import the tested module:

/* maths_fns.test.js */

import Math_fns from './math_fns.re'

test('addition', () => {
  const num1 = 10
  const num2 = 12

  expect(Math_fns.add(num1, num2)).toBe(22)
})

For more documentation on the Jest API, see bs-jest

Importing non-Reason files

You can require CSS files with:

[%bs.raw {|require('./App.css')|}];

or any other kind of file (like SVG's) with:

let logo : string = [%bs.raw {|require('./logo.svg')|}];

Help, Tips, and Tricks

My app won't compile on a fresh install

Try running npm install in your project directory. This helps refresh missing dependencies sometimes.

If this still does not work, make sure your file path does not include any spaces.

I got a SyntaxError after `yarn start` or `npm start` Try upgrading your Node to version 8 or later.

My editor isn't autocompleting

Editor support is provided by Merlin. To generate a .merlin file, run the app with npm start or yarn start.

See our full editor integration guide here: https://reasonml.github.io/docs/en/editor-plugins.html

I don't want reason-scripts to clear my terminal

Use FORCE_COLOR=true react-scripts start | cat - as your start command instead

Reason is awesome! Where can I learn more?

Checkout our fancy website: https://reasonml.github.io/!

We also have a very active Discord to come talk about Reason, and ask for help: https://discordapp.com/invite/reasonml

More Repositories

1

ReasonablyTyped

💠 Converts Flow and TypeScript definitions to Reason interfaces
OCaml
518
star
2

material-resume

✒️ A fancy resume template
HTML
180
star
3

bs-loader

📻 Bucklescript loader for Webpack and Jest
JavaScript
143
star
4

reason-dre

Declarative Bindings for ReasonML
OCaml
41
star
5

Analog

Experimental implementation of Angular components
TypeScript
32
star
6

retypes

📇 Index of curated and automatically generated JS bindings for ReasonML
OCaml
25
star
7

ava-rethinkdb

🔗 RethinkDB helpers for AVA
JavaScript
23
star
8

horizon-devtools

🌅 Devtools for Horizon
JavaScript
21
star
9

styled-scss

A Sass to JavaScript and React compiler
OCaml
16
star
10

Numix-Circle-OSX

⚪ Numix Circle Icons for OS X
10
star
11

HzQL

⚡ Data Fetching for React Using Horizon 2
JavaScript
8
star
12

jadelint

🐉 A linter for the Jade templating language
CoffeeScript
6
star
13

advent-of-code-2017

Advent of Code 2017
OCaml
5
star
14

reason-on-glitch

ReasonML example on Glitch
OCaml
4
star
15

reyle

☀️ Managing styles in style
JavaScript
4
star
16

redux-reaction

💥 Keeping your Actions and Reducers in the same place
JavaScript
3
star
17

libk

Middleware for Koa@next
JavaScript
2
star
18

standard-ts

TypeScript Standard Style
TypeScript
2
star
19

circleci2-jbuilder

CircleCI 2.0 build image for jbuilder-based OCaml projects
2
star
20

reason-angular

uhhh
JavaScript
1
star
21

codacy-coffeescript

☕ Offers coffeescript support for Codacy
CoffeeScript
1
star
22

quill-authorship

Authorship and change tracking for QuillJS
JavaScript
1
star
23

cedh.guide

Source code for cedh.guide
TypeScript
1
star
24

AdventOfCode2018

Solutions for the Advent of Code 2018 using Swift 😄
Swift
1
star
25

angular-template-tag

Use ng-templates inside of <template>
1
star