Hi everyone!
I’m trying to optimize my bundle size in a project based on NextJS and ryyppy bindings in particular. I’ve got a fat component CdekWidget
(done in ReScript) that would be better to load later. So, I’m going to use the NextJS dynamic import.
I’ve done it before in the JS-land, but in this case I’d like to stay in ReScript. So, here what I’ve got:
module DynamicCdekWidget = {
let makeProps = () => Js.Obj.empty() // <- 1
let make = {
open Next.Dynamic
dynamic(
() =>
import_("./Static/CdekWidget.bs.js") // <- 2
->PromiseX.map(x => x["make"]), // <- 3
options(~loading=() => <MaterialUi.CircularProgress />, ~ssr=false, ()),
)
}
}
// Later use <DynamicCdekWidget /> as a regular component
This works fine. Problem solved. However, I see three annoyances here, marked as 1, 2, 3. And I’m not sure that’s the canonical way to go.
- Since I don’t use
@react.component
here, I have to definemakeProps
for myself. Looks like a boilerplate - Here I should know the exact path to
.bs.js
. I suspect this is inevitable, but who knows, perhaps some magic possible to just mention a module name and the path comes out automatically - I have to tweak the import result since ReScript components don’t provide the default export (aren’t they?). Not a big problem, but boring.
In summary, this works, but looks much more bloated then the plain-JS version which is one-liner basically. So, I wonder, am I doing it right?