Converting a Rollup-based Svelte SPA to SvelteKit #4595
dummdidumm
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
I'm hoping to convert an SPA (back) to svelte-kit in a few months, so this will be helpful, but I'll also need to address other problems. Does your solution happen to do any of the following?
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I just converted a small to medium sized application based on Rollup and third-party router to SvelteKit. I'm putting some notes in here for those who are interested in the conversion process:
emitDecoratorMetadata
, SvelteKit which uses Vite which uses ESBuild doesn't. Luckily it still works if you add explicit@inject(ClassToInject)
in from of every contructor injection. You still need to provide some library forReflect.getMetadata
to exist elsetsyringe
errors out, there's an open issue requesting to change thatsvelte-spa-router
previously. Conversion to SvelteKit's file-based routing was straightforward.use:link
just became unnecessary,replace
becamegoto
.cjs
since it's written with CommonJS syntax.rollup.config.js
was removed, it didn't have anything special in there excpect path aliases. These were moved tokit.vite.resolve.alias
without problems. There was one usage of the Rollup replace plugin to use environment-specific variables, which was easy to move into the alias array (no.env
file usage in this project). The alias needed__dirname
to exist which isn't the case in ESM so it's created "manually". The folder that needed to be deployed waspublic
, and to not change that, I adjusted theadapter-static
-setting for that. Thesvelte.config.js
now looks like this:tsconfig.json
is the one from SvelteKit with some minor enhancements:hooks.ts
with the following:public
, I just moved them over toassets
where SvelteKit expects these to appear. I merged the oldindex.html
into theapp.html
. After that, there wasn't anything left inpublic
that was necessary so I deleted it and put it in.gitignore
, it became the build output (also seesvelte.config.js
)Overall this was a nice experience and was easier than I thought. Hope this helps someone!
Beta Was this translation helpful? Give feedback.
All reactions