Replies: 3 comments 1 reply
-
Small bump on this one @jacob-ebey, @pcattori, @ryanflorence. |
Beta Was this translation helpful? Give feedback.
-
We have the same requirement when sharing loaders in a monorepo context.
Thanks for the solution, that does the job. 👍 |
Beta Was this translation helpful? Give feedback.
-
Stumbled across this "issue" now as well. We run a mono-repo using NX and have multiple libraries generated that we would like to denote as "server only" libraries. For now we've had to resort to |
Beta Was this translation helpful? Give feedback.
-
Howdy!
We're creating a CMS based on Remix, and our package (
@fasterfront/cms
) exports two functions,usePageData
(wrapper ofuseLoaderData
) andpageLoader
(to be used as theloader
of your route).The general goal is to provide a quick way to get all data needed for a specific route, eg:
On our package's
index.ts
file we have something likeexport { pageLoader } from './pageLoader.server'
. We assumed Remix compiler would strip this from the browser bundle, but it didn't.We tried many different approaches (eg exporting a function and only requiring the file on-the-fly if
window
is not present), but we couldn't find a way to leave our server-side code out of the consumer's browser bundle.Then I decided to take a look at Remix compiler code, and I figured out that it uses the
emptyModulesPlugin
only when the.server.[ts|tsx|js|jsx]
is inside the consumer'sapp
folder:Although it's understandable that we shouldn't assume that all 3rd party libraries follow Remix convention, we should provide a escape hatch, so libraries can "inform" Remix compiler that a specific file should only be used in the server.
Otherwise, our "solution" for now is to have a
cms
and acms.server
file on the consumer'sapp
root that just re-exports the functions from the library in order to make sure "server" code doesn't appear in the bundle. We'd like to avoid this extra friction.Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions