This repo is a demo of getting Remix to be served via NestJS. In the future, I will package up the code and publish it as an NPM module after I've worked out the kinks.
- Clone this repo.
- Create a new NestJS app using
nest new
. - Install
@remix-run/
packages:npm i --save @remix-run/{express,node,react,serve}; npm i --save-dev @remix-run/{dev,eslint-config}
- Install
concurrently
so we can runremix watch
andnest build --watch
at the same time:npm i --save-dev concurrently
. - Add the required Remix files from this repo:
remix.config.js
,remix.env.d.ts
. Copy thetsconfig
files. - Add the
app
directory from this repo. - Add the
src/remix
directory from this repo. - Update your
AppModule
to use@RemixModule()
instead of@Module()
and provide the required RemixConfig. - Update the package.json
start:dev
script to match the one in this repo. This now will start the Remix and Nest builds. - Relish in the glory of Remix and NestJS.
Use the RemixController['getLoadContext']
function to pass services and data to Remix loaders via the LoaderArgs['context']
property.
Ideally, we can pass the whole NestJS IoC container and let loaders pluck services out from that (or do something even more clever). However, in trying to pass the singleton ModuleRef
from NestJS ended up with a ton of Remix build errors due to missing packages (packages that are optionally required, but with how Remix builds, it wants them to exist or be wrapped in a try/catch).
There's probably a fair bit of issues. I haven't tested this much yet. Feel free to report any issues. Truthfully, I probably will not address them but will happily merge and pull requests.
- Provide a way to get NestJS providers to Remix loaders. Alternatively, leverage NestJS to BE the loader function for a Remix view.
- Pull the
src/remix
folder out into an NPM package after #1 is solved. - Merge the NestJS and Remix builds into one process instead of using
concurrently
. This will remove unnecessary dependencies and hopefully make a more stable and friendly developer experience. However, there's lots of logic going into Remix's build that I am wary of. - Get hot module reloading for Remix changes through NestJS's dev server.
Thanks to AndrewsRodH for the starting point.