if I have an env file .env.development in the root directory, this works:
import { PUBLIC_FOO } from '$env/static/public';
...
console.log(PUBLIC_FOO); // works
However, if I have a custom env directory, it does not. But import.meta.env
does work (for VITE_
properties as mentioned in the vite docs, but not PUBLIC_
)
// vite.config.ts
export default defineConfig({
plugins: [sveltekit()],
envDir: 'env',
test: {
include: ['src/**/*.{test,spec}.{js,ts}'],
}
});
// foo.svelte
import { PUBLIC_FOO } from '$env/static/public';
...
console.log(PUBLIC_FOO); // does not work
console.log(import.meta.env.PUBLIC_FOO) // does not work
console.log(import.meta.env.VITE_FOO) // works