You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
// In SvelteKit:import{DATABASE_URL}from'$env/static/private';// In Bun scripts:constDATABASE_URL=process.env.DATABASE_URL;// or Bun.env.DATABASE_URL
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 to Bun.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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
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