Why ExpressJs and SvelteKit?
SvelteKit is an amazing web development framework and is quickly developed. However, there’re many issues that SvelteKit doesn’t support yet and developers need to fall back on server applications like ExpressJs.
This tutorial introduce you how to combine use SvelteKit as a handler in ExpressJs project.
Init SvelteKit project with express and esbuild
Create index.js
at project root
Create esbuild.js
at project root
You need the config banner.js
because esbuild
doesn’t polyfill dynamic import with require
function. This script simply overwrites the build/index.js
from SvelteKit with the index.js
of express.
Setup package.json
Discussion
With this building config, you can deploy the build folder
and start the server with command node build
. You can make urself a script for live reload while developing the app with nodemon
Conclusion
You should stay with SvelteKit as much as possible and only implement this solution when you need features that SvelteKit doesn’t support yet.