This codemod updates Svelte component instantiation and event handling for Svelte 5:
- Converts new Component({ target })tomount(Component, { target }).
- Adds the mountimport fromsvelteif not present.
- Replaces $onmethod calls with theeventsproperty in the mount options.
This ensures compatibility with Svelte 5's function-based components and new event handling.
Before
import App from './App.svelte';const app = new App({ target: document.getElementById('app') });app.$on('event', callback);
After
import { mount } from 'svelte';import App from './App.svelte';const app = mount(App, {target: document.getElementById('app'),events: { event: callback },});
Build custom codemods
Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community