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

feat: expose loadConfigFromFile API #1403

Merged
merged 1 commit into from Jan 7, 2021

Conversation

antfu
Copy link
Member

@antfu antfu commented Jan 6, 2021

For advanced usage like https://github.com/antfu/vite-ssg to have better controls over user configs

@yyx990803
Copy link
Member

Is resolveConfig not enough for the use case?

@antfu
Copy link
Member Author

antfu commented Jan 7, 2021

I found a workaround by asking users to have this line in their config and inject the env on the go:

Vue({
  ssr: !!process.env.VITE_SSG
})

My use case is fulfilled and I am ok with closing. However, I think there are still some limitations toward programmatic usages:

Both build() and resolveConfig() accept a inlined UserConfig for their first argument. While resolveConfig() returns ResolvedConfig which also contains Vite's internal plugins. There is no easy way to read users' raw config to have some context-aware operations without writing a custom loader for the config.

For example:

const config = await resolveConfig()

// manipulate the config, injecting plugins, etc.

await build(config) // errors on both type and runtime

By exposing loadConfigFromFile() we can have something like:

const config = await loadConfigFromFile('vite.config.js')

// manipulate the config, injecting plugins, etc.

await build(config, '') // assuming passing an empty string to disable the config file merging.

@yyx990803
Copy link
Member

Yeah makes sense.

@yyx990803 yyx990803 merged commit 9582171 into vitejs:main Jan 7, 2021
@antfu antfu deleted the feat/expose-load-config branch January 7, 2021 01:34
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

Successfully merging this pull request may close these issues.

None yet

2 participants