Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotenv and debugging #2091

Closed
basaran opened this issue Aug 4, 2021 · 2 comments
Closed

dotenv and debugging #2091

basaran opened this issue Aug 4, 2021 · 2 comments

Comments

@basaran
Copy link
Contributor

basaran commented Aug 4, 2021

Describe the problem

I have been trying to expose DEBUG flag to debug server side endpoints and hooks through .env using dotenv package but I couldn't succeed.

Describe the proposed solution

It seems vite has some configuration options that can be used, but I'm not sure how to place this to svelte.config.js

vitejs/vite#2676

import { defineConfig, loadEnv } from 'vite';

export default defineConfig(({ mode }) => {
  Object.assign(process.env, loadEnv(mode, process.cwd()));

  return {
    // ...
    base: process.env.VITE_ASSET_URL
  }
});

Alternatives considered

I was able to workaround this by using dotenv-cli and package.json

	"scripts": {
		"dev": "dotenv -e .env -- svelte-kit dev --port 4000 --host 0.0.0.0",
		"build": "svelte-kit build",
		"preview": "svelte-kit preview",
		"carbon": "gulp -f gulpfile.cjs"
	},

Importance

nice to have

Additional Information

If there is an official way, it would be nice to have this in the docs.

@benmccann
Copy link
Member

We're working on making server-side environment variables easier to use. See vitejs/vite#4192

In the meantime, I've documented everything I know at https://kit.svelte.dev/faq#env-vars

@basaran
Copy link
Contributor Author

basaran commented Aug 4, 2021

thank you, I had read both of them. But please do note process.env.DEBUG and process.env["DEBUG"] appear not to be same. It's alright if you are accessing them yourself, but an npm package like debug, I suppose expects process.env.DEBUG and not the latter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants