Svelte 4 migration and accompanying fixes
dmitrysmagin opened this issue · comments
Hello.
It turns out that Elderjs could be easily migrated to Svelte 4.
It needs minor code fixes (that could be applied as well without migrating to Svelte 4).
Example patch:
dmitrysmagin@0b82c2a
I haven't created the pull request, because this patch is applied on top of v1.7.5 and still uses rollup. I haven't tried to use esbuild yet.
So, minor fixes that could be applied right away without breaking anything:
Both in Svelte 3 and 4 PreprocessorGroup could be imported from 'svelte/types/compiler/preprocess', but Svelte 4 removes types.d.ts in favor of index.d.ts
'Number' is not a Typescript type, but 'number' is. With Svelte 4 it gives a compile error, but Svelte 3 passes it.
Svelte 4 drops the field 'format' from CompileOptions, so the target is always 'esm'.
Also, CompileResult type doesn't have 'js.dependencies' field so assigning it has no sense. Dependencies tracking is needed here for hot recompile, so we can use the local var with this.addWatchFile());
Other than that, for successful migration to Svelte 4 some packages are needed to be upgraded:
svelte - to 4.2.7
rollup - minumum to v2.78.0, otherwise hooks like onMount won't work in hydration mode
@rollup/plugin-node-resolve - to 15.2.3
jest - to 29.7.0
typescript - to 5.3.2