Giter VIP home page Giter VIP logo

bucklescript-monorepo's Introduction

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, 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:

  "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:
   "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"
   }
  1. Add "fetched-dog-pictures" as a dependency in the root bsconfig.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.

bucklescript-monorepo's People

Contributors

anmonteiro avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.