can reasonreact import the react module from cdn?

Technically, yes you can, but it’s not going to be as easy as going with the npm flow and using a bundler.

The ReasonReact bindings are written in a way that produces output JavaScript that imports modules like:

import * as React from "react";

(If using ES6 module style.)

If using a CDN you would probably want an output that looks like this:

import * as React from "https://some.cdn/react";

The syntax (from the ReasonReact repo) that controls the output JS is:

[@bs.module "react"]
external createElement: (component('props), 'props) => element = "createElement";

If you changed it to:

[@bs.module "https://some.cdn/react"]
external createElement: (component('props), 'props) => element = "createElement";

…then you’d get the desired output. But the problem is then you need to change the sources … i.e. maintain or find forked bindings for React for that CDN. Or set up some code automation that does a find-and-replace of [@bs.module "react"] with [@bs.module "https://some.cnd/react"]. So either way, it’s not as simple as using a bundler.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top