Google Apps Script?

I have just arrived. Sorry in advance if this is a well discussed and solved issue – Claude AI seems to think otherwise.

Seeing as rescript generates javascript, can it be convinced to output javascript suitable for uploading to a Google Apps Script project?

-Bruce

2 Likes

Claude is right.

I think for Google Apps Script you need a single JS file so you would need a bundler anyway to get to that. ReScript only outputs one JS file per .res file.

A minimal setup with esbuild could look like this:

rescript.json:

{
  "name": "my-app-script",
  "sources": [
    {
      "dir": "src",
      "subdirs": true
    }
  ],
  "package-specs": {
    "module": "esmodule",
    "in-source": true
  },
  "suffix": ".res.mjs"
}

package.json:

{
  "name": "my-app-script",
  "scripts": {
    "build:res": "rescript build",
    "build": "npm run build:res && node scripts/build.mjs"
  },
  "devDependencies": {
    "esbuild": "^0.25.0",
    "rescript": "^11.1.0"
  }
}

scripts/build.mjs:
Disclaimer: suggested by Codex.

import { build } from "esbuild";

await build({
  entryPoints: ["src/Main.res.mjs"],
  bundle: true,
  format: "iife",
  platform: "neutral",
  outfile: "build/Code.js",
  banner: {
    js: "var exports = undefined; var module = undefined; var require = undefined;",
  },
});

And if that does not work you probably also need to set the runtimeVersion in the manifest to V8.