bucklescript compiler plugin for rollup.js
works with both ReasonML and OCaml
First install bs-platform in your project
npm i -D bs-platformcreate a bsconfig.json for Bucklescript in the root directory of your project
and remember to specify "package-specs" as ["es6"], so that rollup can consume it.
{
"name": "hello",
"sources": ["src"],
"bs-dependencies": ["reason-react"],
"reason": {
"react-jsx": 2
},
"package-specs": ["es6"],
"refmt": 3
}Finally, install rollup-plugin-bucklescript
npm i -D rollup-plugin-bucklescriptand add it to your rollup config.
import bucklescript from 'rollup-plugin-bucklescript'
export default {
input: 'src/main.re',
output: {
file: 'dist/main.js',
format: 'cjs',
},
plugins: [
bucklescript()
],
}All the settings are taken from bsconfig.json, but few options can be overridden.
include and exclude each a minimatch pattern, or array of minimatch patterns, which determines which files are complied by Bucklescript.
By default all .re and .ml are included and all .rei and .mli are excluded.
moduleTo specify bucklescript output type for rollup to consume.
Note: Please check the Caveats section
...
plugins: [
bucklescript({
module: 'es6'
})
]inSourceTo use bs-loader with bsb's in-souce builds,
add the inSource option to your loader config:
...
plugins: [
bucklescript({
inSource: false
})
]cwdThis option specifies what directory to run bsb from.
...
plugins: [
bucklescript({
cwd: 'path/to/dir'
})
]showWarningsControls whether bsb compile warnings are shown. Defaults to true.
...
plugins: [
bucklescript({
showWarnings: true
})
]includeStandardLibraryNote: This is an advance feature and may not work as intended
Bucklescript comes with OCaml standard library complied to javascript.
Choose whether to bundle functions from standard library.
Defaults to true.
Check the examples folder in the github repo.
Please use es6 for module option as rollup works only with es modules.
But this breaks integration with with react,
thought it can be easily solved by following the helpful error message provided by rollup.
or check the react example folder.
bsb-js and read-bsconfig.MIT