BuckleScript Monorepo example
This small example, boostrapped from the react-hooks
theme (bsb -init . -theme react-hooks
), showcases a simple monorepo setup for BuckleScript
projects.
It strives to be as simple as possible and makes the following design choices:
- No complicated monorepo tools
- yarn supports
link:/path/to/sub/package
which works well enough for the purposes of this demonstration (and arguably most projects).
- yarn supports
- No reliance on
bsb -w
- BuckleScript's watch mode isn't aware of linked dependencies
- Watch mode is implemented by reading the source directories BuckleScript is
aware of (just like
bsb
does) and passing them to entr, a simple utility to run commands when files change.
- No reliance on
bsb
bsb
is written in JavaScript, and I've got better things to do than to wait for Node.js startup. This example calls the nativebsb.exe
binary directly.
Package structure
The file structure is the same as the react-hooks theme, with the exception
that one of the subdirectories in src
(FetchedDogPictures
) is now its own
library. The bsconfig.json
file is changed accordingly:
"sources": {
"dir": "src",
- "subdirs": true
+ "subdirs": [
+ "ReasonUsingJSUsingReason",
+ "ReducerFromReactJSDocs",
+ "BlinkingGreeting"
+ ]
},
Additionally, we place a bsconfig.json
inside the src/FetchedDogPictures
folder, add a name to the library (fetched-dog-pictures
), and:
- Add
"fetched-dog-pictures"
as dependency inpackage.json
:
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1",
- "reason-react": ">=0.8.0"
+ "reason-react": ">=0.8.0",
+ "fetched-dog-pictures": "link:./src/FetchedDogPictures"
}
- Add
"fetched-dog-pictures"
as a dependency in the rootbsconfig.json
:
"bs-dependencies": [
"reason-react",
+ "fetched-dog-pictures"
],
A small note: this example allows to structure BuckleScript projects in self-contained libraries, which should feel familar for folks that have used dune.
Running the example
Note: this repository is set up to consume bs-platform
using
Nix simply because that's the package manager I use.
It should work if you're consuming bs-platform
from NPM, as long as the
references to $BSB_PATH
and ./node_modules/.bin/bsb.exe
are replaced
appropriately.
To run the example, run:
$ make
This will start a watcher process and serve a bundle via webpack-dev-server
.
License & Copyright
The code contained within this repository is in the public domain. Consult the LICENSE file for more information.