Closed linear[bot] closed 6 months ago
Is it not possible to create virtual modules in vite instead of paraglide-js-next build
?
No. (almost?) All frameworks using file-based routing read directly from FS. They also don't always do it in the same process, so we can't just shim fs with our own thing. We unfortunately need to shuffle around real files.
uhh tough one. if it's the right approach, i guess we have to do it :/
The only alternative here would be the postprocessor that I proposed, but that would also have it's own suite of challenges:
IMO the file-copy one is the better approach. All the challenges at least have a clear path to fixing them. I suggest we move forward with this
@loris.sigrist we can release this as experimental. the most convincing thing is the fact that only the build script needs to be adjusted, not dev mode.
TLDR: Seems to be the right approach for file-based routers, but will need adaptation for each framework.
Overview
The idea behind this approach is to copy the
routes/
folder (or framework equivalent) for each language during build.We then replace any imports for
messages.js
with the appropriatemessages/lang.js
Prototype findings
{ languageTag: "de" }
on a message by message basis. It may be possible to spot this & not do the transform, but that's more complexity.lib/
folders too? But then, where do we stop?routeId
based routing solution. There we would need to greatly adapt this approach, although it's still useable.None of these are a dealbreaker IMO. I'm fairly confident that this is the best we can do without first-party support from frameworks.
Suggested API
In the prototype, the best API I could come up with is a
paraglide-js build
command. It works similarly todoppler
, in that you pass it the build command you want to run.This allows us to run setup code before the build, and to clean up afterwards.
Technical Challenges
routes/
{ languageTag: "de" }
optionmessages.js
importlanguageTag()
still returns the correct value)This approach does result in a lot of duplication, since you need entirely separate language-detection & routing logic during build and production. We will need to deal with a lot of bugs stemming from this duplication, but I don't really see a better way right now.
I do have a version that mostly works, but still suffers from a lot of these edge-cases