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

Config Function #3077

Closed
Crisfole opened this issue Dec 20, 2021 · 6 comments
Closed

Config Function #3077

Crisfole opened this issue Dec 20, 2021 · 6 comments
Labels
feature request New feature or request

Comments

@Crisfole
Copy link
Contributor

Describe the problem

Much like vite, some configuration options for svelte kit are dependent on the mode you're running in. In particular the hostHeader which is rarely wanted when you're running locally (some docker-configs excepted). Currently we have to rely on environment variables which are OK, but less smooth a path than vite's strategy of accepting either a function or a config object.

Describe the proposed solution

I'd love for svelte to accept either a config object, or a function that receives some environment information and returns the config object. I brainlessly spent about an hour this morning confusing the Vite and svelte configurations and assuming I could use a function for both. The hour wasted was my fault, but it did reveal a feature that would be simple and nice.

Alternatives considered

Environment variables.

Importance

would make my life easier

Additional Information

No response

@bluwy bluwy added the feature request New feature or request label Dec 23, 2021
@vpanyushenko
Copy link

Today for something like hostHeader, you can do something like:

const config = {
    kit: {
        target: "#svelte",
        hostHeader: process.env.NODE_ENV !== "development" ? "x-forwarded-host" : "",
    }
}

export default config;

And by checking the process.env.NODE_ENV, I guess you could write a function that could return a custom config object.

const config = yourCustomFunction(process.env.NODE_ENV)

export default config;

@dominikg
Copy link
Member

fyi: this RFC sveltejs/rfcs#59 describes a solution for svelte config with builtin function support.

@Rich-Harris
Copy link
Member

Given that top-level await is a thing, do we need function support?

@bluwy
Copy link
Member

bluwy commented Jan 27, 2022

Perhaps a function would make more sense if we implement #1258

@Crisfole
Copy link
Contributor Author

@Rich-Harris valid question. I think the consistency across APIs would make it more usable, but I'm easily persuaded here. I think I'm just too old - forgot top level await was allowed.

@Rich-Harris
Copy link
Member

Going to close this for the sake of tracker hygiene unless another use case presents itself

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

No branches or pull requests

5 participants