bs-loader
Bucklescript loader for Webpack
This works with both Reason and OCaml files, thanks to Bucklescript 1.5.
Installation
npm install bs-loader
Setting up Bucklescript
First create a bsconfig.json
for Bucklescript:
{
"name": "hello",
"sources": [
"src"
],
"bs-dependencies": [
"reason-js",
"rehydrate"
],
"reason": {
"react-jsx": true
}
}
We will also need reason-js
, rehydrate
, and bs-platform
. Your package.json
should look something like this:
{
"name": "reason-webpack",
"private": true,
"version": "1.0.0",
"description": "",
"scripts": {
"build": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"bs-loader": "^1.0.0",
"bs-platform": "^1.5.0",
"reason-js": "0.0.16",
"rehydrate": "git+https://github.com/reasonml/rehydrate.git",
"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:
const path = require('path')
module.exports = {
entry: './src/entry.re',
output: {
filename: 'out.js',
path: path.resolve(__dirname, 'build')
},
module: {
rules: [
{ test: /.(re|ml)$/, use: 'bs-loader' },
]
},
resolve: {
extensions: ['.re', '.ml', '.js']
}
}