Skip to content

dotenv and debugging #2091

@basaran

Description

@basaran

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions