Write ReasonML and Bucklescript in your existing babel projects
Functional programming is cool. ReasonML is cool. Bucklescript is cool. But you may not have the opportunity to start a new project or rewrite an existing one in those languages. In that case, babel-plugin-bucklescript
is here for you!
babel-plugin-bucklescript
lets you easily add ReasonML or Bucklescript projects to your existing codebases via a babel plugin. It relies on existing tools like bs-platform
to work. And since bs-platform
is amazingly fast, so is this plugin. It works for node-style require
calls as well as ES2015 import
statements.
To get started, add babel-plugin-bucklescript
and bs-platform
to your project's dev dependencies.
# with good ol' npm
npm install -D babel-plugin-bucklescript bs-platform
# with yarn
yarn add -D babel-plugin-bucklescript bs-platform
After that's finished, add the plugin to your babel dependencies. By default, this plugin will assume you're using the js
package spec. For more information, see the bucklescript manual on using bsb.
{
"plugins": ["babel-plugin-bucklescript"]
}
If, however, you want to compile to amdjs
or es6
, you can pass that in as an option.
{
"plugins": [
["babel-plugin-bucklescript", { "module": "es6" }]
]
}
Finally, you'll want to add a bsconfig.json
file in the root of your project. Note that by default, bsb
will compile to a folder called lib
in the root of your project, no matter where your source code is. Take that into account when building your project. As of right now, this plugin only supports that compilation directory.
{
"name": "your-cool-project",
"sources": ["src"],
"bs-dependencies": ["reason-react"],
"reason": {
"react-jsx": 2
},
"package-specs": ["commonjs"]
}
/* In a file called test.re */
let add x y => x + y
// In a file called index.js
const { add } = require("./test.re");
console.log(add(1, 2)) // -> 3
- Full examples
- Tests
- Integration testing with multiple types of projects
Issues and Pull requests are both welcomed! Prettier is enabled by default as a pre-commit hook, but feel free to add it to your editor.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.