Using vite to run the RedwoodJS API with hot-reloading, and building to a single file for server deployment.
This is not meant to be a tutorial, but a reference for core team members to understand the setup. If you choose to do this, you are truly on your own, and there are likely RedwoodJS features that will not work as expected.
-
Add a
main.ts
file to the directory, this is the new server entry point- This file is responsible for starting the fastify server and importing the functions
- It has a single export of
redwoodApp
which is the fastify server, which is used by vite-plugin-node
-
Add a
vite.config.mts
file to the directory, this is the new vite configuration. It replicates a lot of the babel plugins that RedwoodJS uses, and knows to look atredwoodApp
for the server frommain.ts
. -
functions/graphql.ts
switches to use the vite glob import syntax
- Run dev server:
vite
- Create deployable server:
vite build
(createsapi/dist/main.mjs
)
- SDL does not updated when you make changes to those files (maybe need to explore HMR API or vite plugin)
- There isn't a hook now for generating the schema in a text file (can use envelope plugin + graphqljs
printSchema
in user-land) - SDL codegen now has a reason for a watcher mode, could come with a 'vite plugin' which simply is given filepaths