Hi, I’m working on a project with builds for Browser, React Native, and Electron. I’ve written a seperate IO module for each platform, each module has the same interface so they can be used interchangeably. I’d like to be able to switch module is being used at bundle time, while retaining type safety
I tried using Old Docs, but this can only target one platform at a time, and I’d like to develop on multiple platforms simultaniously.
I don’t see any reason why this wouldn’t work. E.g., say you have files arranged like:
Then in src/io/IO__Target.ml you can define:
module Browser = IO__Target__Browser
module ReactNative = IO__Target__ReactNative
module Electron = IO__Target__Electron
module type S = sig ... end
module Make(IO : S) = struct ... end
module Platform = Make(
#if defined TARGET && TARGET = "browser" then
#else if defined TARGET && TARGET = "reactnative" then
#else if defined TARGET && TARGET = "electron" then
You can also experiment with different file and folder layouts, but this should be a good starting point. To build for each platform just pass in the env variable for the platform, e.g. TARGET=browser rescript.