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
Uh oh!
There was an error while loading. Please reload this page.
-
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.getMetadatato exist elsetsyringeerrors out, there's an open issue requesting to change thatsvelte-spa-routerpreviously. Conversion to SvelteKit's file-based routing was straightforward.use:linkjust became unnecessary,replacebecamegoto.cjssince it's written with CommonJS syntax.rollup.config.jswas removed, it didn't have anything special in there excpect path aliases. These were moved tokit.vite.resolve.aliaswithout 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.envfile usage in this project). The alias needed__dirnameto 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.jsnow looks like this:tsconfig.jsonis the one from SvelteKit with some minor enhancements:{ "extends": "./.svelte-kit/tsconfig.json", "compilerOptions": { "strict": true, "experimentalDecorators": true, "baseUrl": "src" } }hooks.tswith the following:public, I just moved them over toassetswhere SvelteKit expects these to appear. I merged the oldindex.htmlinto theapp.html. After that, there wasn't anything left inpublicthat 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