zth / rescript-relay-router

MIT License
16 stars 3 forks source link

findGeneratedModule logic duplicated #17

Closed zth closed 2 years ago

zth commented 2 years ago

Logic exists in both the RescriptRelayVitePlugin and in lookup.mjs. Figure out why and dry up.

Kingdutch commented 2 years ago

Could you elaborate on what this is used for? Why do we need special module resolution rather than allowing Rescript/Vite/Node (i.e. our environment) to do this for us?

zth commented 2 years ago

In short:

Dynamically importing via %relay.deferredComponent, we only know what module to import, but there's no way to know where the generated ReScript file for that module (which is what we'll want Vite to import) is located. And ReScript does not (yet) give us tools to look that up. So that's what findGeneratedModule does, it takes what %relay.deferredComponent outputs, which is roughly import("@rescriptModule/WhateverModule") and looks up where WhateverModule.mjs is located, so we can point Vite to the right file.

Makes sense?

Kingdutch commented 2 years ago

Oh right okay! Yeah because Rescript usually makes the import * as RescriptModule from "../calculated/module/path.ext" but we can not make it do the same for a import("../calculated/module/path")

Yeah makes sense!