https://github.com/anmonteiro/bucklescript-monorepo
Example of a BuckleScript monorepo setup
https://github.com/anmonteiro/bucklescript-monorepo
Last synced: 7 days ago
JSON representation
Example of a BuckleScript monorepo setup
- Host: GitHub
- URL: https://github.com/anmonteiro/bucklescript-monorepo
- Owner: anmonteiro
- License: unlicense
- Created: 2020-06-01T23:55:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T18:45:00.000Z (about 3 years ago)
- Last Synced: 2024-05-22T21:26:40.035Z (over 1 year ago)
- Language: Reason
- Size: 1.34 MB
- Stars: 31
- Watchers: 5
- Forks: 2
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - bucklescript-monorepo
README
# 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).
- 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](http://eradman.com/entrproject/), 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 native `bsb.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:
```diff
"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:
1. Add `"fetched-dog-pictures"` as dependency in `package.json`:
```diff
"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"
}
```
2. Add `"fetched-dog-pictures"` as a dependency in the root `bsconfig.json`:
```diff
"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](https://dune.build).
## Running the example
_Note_: this repository is set up to consume `bs-platform` using
[Nix](https://nixos.org/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:
```sh
$ 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](./LICENSE) file for more information.