ReasonML for Google Cloud Functions


#1

I am new to ReasonML but an experienced OCaml programmer. I am wondering if anyone has any experience writing ReasonML for Google Cloud Functions, which has support for Node.js 1.6 and 1.8.

Thanks,
Hadil


#2

Hey, I did it once for a fun project. It was relatively straight forward, just a small binding for the trigger you want to use is needed. For a HTTP trigger you can actually reuse the bindings of bs-express, because the request and response object have the exact same shape.
I highly suggest that you bundle the resulting .js files with e.g. webpack, even though the cloud functions docs suggest just uploading the node_modules folder. Reason for this is that the bucklescript dependency ist quite big (200MB I think) which you will need to upload with your function.
Instead I had a webpack bundled js of only couple hundreds KB.


#3

In some video in the firebase channel I remember the setup they used for typescript and it would avoid the problem you mention of shipping the dependency of bucklescript in the functions folder.

The setup they had was:

  • package.json : Top level dependencies and dev dependencies (bucklescript, bs-express, etc)
  • src/ : Application sources
  • functions/ : Where you output your JS files after compilation
  • functions/package.json : Runtime/production dependencies

If they needed to use an npm package, they would put it in functions/package.json, and if they needed it for tests or something at dev time, then they’d duplicate it in the top level package.json.

This means you may have duplicate entries in the package.json files, but it also means you have more flexibility when it comes to development deps and production ones.


#5

The problem with this is that - depending on what you use in your ReasonML code - bucklescript will compile with runtime dependencies of bucklescript backed in. So that bucklescript becomes a dev and production dependency. There are efforts to split the two, but we are not there yet as far as I know.


#6

Hi Alex, do you have this project shared anywhere or any advice on how to set this up with the gcloud boilerplate?


#7

Hi Alex, I would really appreciate information on using webpack with BS. I am struggling to get it to work.

Thanks,
Hadil


#8

I currently have webpack with BS. It’s pretty straight forward since nothing changes from your standard configuration. You need to start a new topic though, otherwise it might be a thread hijack.


#9

@josgraha I don’t have a example published. I might do a write-up with a example repo in the future, but currently I am super busy with other stuff.

@hadils I suggest you open a new thread with the specific webpack issue you experience!