import target from "#app/target";
target; // "desktop" | "web"
import IndexPage from "#components/IndexPage.jsx";
export default {
get() {
// statically (TS), this needs to resolve to the correct component for live-bindings between server and client
// in runtime (JS), this needs to resolve to `view("IndexPage", props);`
return IndexPage({ posts: [{ id: 0, title: "Hello, world!" }] });
},
};
Other uses also possible, like importing stores from anywhere, provided we can make sure that operations are still transactionalised.
With export conditions, we should even make it possible to import stores from clientside components, translating the implementation to a fetch call to some canonical API route that accesses the database and returns the results. But this could quickly become a security nightmare unless done conservatively and in an extremely guarded way (only reads, and possibly hardcoding the queries on the server so it doesn't become a universal mechanism to access the database).
Considerations:
Needs to work both clientside (esbuild) and serverside (node/bun/deno); esbuild currently bundles from ., not from ./build, for hotreloading during dev
TS should be supported to the extent possible
It should be compatible with both dev (build&serve) and prod (build now, serve later) environments
Global bare imports.
(Relates to https://github.com/primatejs/primate/issues/122)
Other uses also possible, like importing stores from anywhere, provided we can make sure that operations are still transactionalised.
With export conditions, we should even make it possible to import stores from clientside components, translating the implementation to a fetch call to some canonical API route that accesses the database and returns the results. But this could quickly become a security nightmare unless done conservatively and in an extremely guarded way (only reads, and possibly hardcoding the queries on the server so it doesn't become a universal mechanism to access the database).
Considerations:
Is currently only possible with Node, as introducing custom loaders isn't supported in Bun (https://github.com/oven-sh/bun/issues/13415) or Deno (https://github.com/denoland/deno/issues/23201). We can only mainline this once Bun and Deno support it.