Bun plugin to use SvelteKit imports in standalone scripts #16833
mquandalle
started this conversation in
Show and tell
Replies: 0 comments
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.
Uh oh!
There was an error while loading. Please reload this page.
-
When using Bun with a SvelteKit application, you often need to run standalone scripts that reuse code from your app. But SvelteKit uses special module imports that don't work outside the SvelteKit context:
This makes it hard to share utility functions between your SvelteKit app and CLI scripts without duplicating code or creating environment-specific wrappers.
I created a simple Bun plugin that resolves SvelteKit's virtual modules, allowing you to use the same imports everywhere:
$env/static/private
→ maps toBun.env
$app/environment
→ returns{ dev: true }
Now you can write shared code once and use it in both your SvelteKit app and Bun scripts without any modifications.
https://github.com/mquandalle/bun-plugin-sveltekit
Beta Was this translation helpful? Give feedback.
All reactions