Use SvelteKit as a handler in the ExpressJs project

chientrm
1 min readJun 17, 2022

--

Use SvelteKit as a handler in the ExpressJs project
Photo by Gabriel Heinzer on Unsplash

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.jsof 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.

--

--

No responses yet