• This repository has been archived on 03/Dec/2018
  • Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • 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

📻 Bucklescript loader for Webpack and Jest

bs-loader Build Status

Bucklescript loader for Webpack


This library is in maintanence mode. Instead of using bs-loader we recommend using bsb' new in-source builds in conjunction with .bs.js extensions:

// bcsconfig.json
{
  "package-specs": {
    "module": "commonjs",
    "in-source": true
  },
  "suffix": ".bs.js",
}

This works with both Reason and OCaml files

Installation

npm install bs-loader

Example

Setting up Bucklescript

First install bs-platform into the project:

$ npm i -D bs-platform

Create a bsconfig.json for Bucklescript:

/* bsconfig.json */
{
  "name": "hello",
  "sources": [
    "src"
  ],
  "bs-dependencies": [
    "reason-react"
  ],
  "reason": {
    "react-jsx": 2
  }
}

We will also need reason-react, and bs-platform. You can install bs-platform globally and use npm link to the link the binary, or install bs-platform as a devDependency. Your package.json should look something like this:

/* package.json */
{
  "name": "reason-webpack",
  "private": true,
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "build": "webpack"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "bs-loader": "^1.0.0",
    "reason-react": "0.1.3",
    "webpack": "^2.2.1"
  },
  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
  }
}

Using the loader

To use the loader you must:

  • Register the .re and .ml extensions with Webpack
  • Configure .re and .ml to use the loader

An example config would look like:

// webpack.config.js
const path = require('path')

module.exports = {
  // Entry file can be a Reason or OCaml file
  entry: './src/entry.re',
  output: {
    filename: 'out.js',
    path: path.resolve(__dirname, 'build')
  },
  module: {
    rules: [
      // Set up Reason and OCaml files to use the loader
      { test: /\.(re|ml)$/, use: 'bs-loader' },
    ]
  },
  resolve: {
    // Add .re and .ml to the list of extensions webpack recognizes
    extensions: ['.re', '.ml', '.js']
  }
}

Usage with Jest

bs-loader includes a transform for usage with Jest. This lets Jest run Reason and OCaml files as tests. An example Jest configuration using bs-loader:

"jest": {
  "moduleFileExtensions": [
    "re",
    "js",
    "ml"
  ],
  "testMatch": [
    "**/src/*_test.re"
  ],
  "transform": {
    ".(re|ml)": "bs-loader"
  }
}

Options

Most of these settings are inferred from your bsconfig.json. These are available for manual override, but might go away in the future.

module

To tell Webpack to load a module type that isn't JS (for example, amd or goog) give the loader a module option. For example, to use AMD modules produced by Bucklescript, use the config

{ test: /\.(re|ml)$/, use: 'bs-loader?module=amd' }

inSource

To use bs-loader with bsb's in-souce builds, add the inSource option to your loader config:

{
  test: /\.(re|ml)$/,
  use: {
    loader: 'bs-loader',
    options: {
      module: 'es6',
      inSource: true
    }
  }
}

cwd

This option specifies what directory to run bsb from. For example, to run bsb from the same directory as your webpack config, use:

{
  test: /\.(re|ml)$/,
  use: {
    loader: 'bs-loader',
    options: {
     cwd: __dirname
    }
  }
}

showWarnings

Controls whether bsb compile warnings are shown. Defaults to true.

More Repositories

1

reason-scripts

🔰 Create a ReasonML and React development environment
JavaScript
628
star
2

ReasonablyTyped

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

material-resume

✒️ A fancy resume template
HTML
180
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