Giter Club home page Giter Club logo

reason-scripts's Introduction


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.

Getting Started

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

This will create a new app the the <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

  • 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 files

Any Reason 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 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" (fun () => {
  let num_1 = 10;
  let num_2 = 12;

  expect (Math_fns.add num_1 num_2) |> 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')|}];

FlowTyped Integration [WIP]

Reason Scripts automatically generates an interface to any library installed with npm and FlowTyped

Importing JS files [WIP]

If you type the exports of a JS file with Flow types, you can use the file directly in Reason. For example, in the file math_fns.js:

// @flow
// math_fns.js

export function add(x: number, y: number): number {
  return x + y;
}

you will be able to access add in a Reason file with:

let run_func x y => Math_fns x y;

reason-scripts's People

Contributors

bebbi avatar bondz avatar bunshar avatar davidascher avatar ekaradon avatar enoahnetzach avatar existentialism avatar frontsideair avatar fson avatar gaearon avatar gaumala avatar jamesblight avatar jayphelps avatar jeffposnick avatar johann-sonntagbauer avatar kellyrmilligan avatar luftywiranda13 avatar n3tr avatar nhajidin avatar pd4d10 avatar pmadar avatar ro-savage avatar rrdelaney avatar ryansully avatar sidoshi avatar simenb avatar timer avatar tuchk4 avatar viankakrisna avatar zaccc123 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.