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: load external config file #516

Open
yjl9903 opened this issue Jan 26, 2024 · 0 comments
Open

feat: load external config file #516

yjl9903 opened this issue Jan 26, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@yjl9903
Copy link
Owner

yjl9903 commented Jan 26, 2024

Clear and concise description of the problem

Vite supports using dotenv .env to pass some config into the application.

However, sometimes our config may be complex with various fields.

Now, unplugin-info supports pass some config with { meta: { ... } } to ~build/meta. But it does not support switch between different env (you must write some if-else or ? : code to support it) and modify vite.config.ts will cause server restart.

Suggested solution

Add another options { settings: '<config file>.{json|yml|...}' }, { settings: { dev: '...', production: '...', ... } }

Add another virtual module ~build/settings to get the content of config file.

For example:

# config.yml
field1: 111
field2: 222
// vite.config.ts

import Info from 'unplugin-info/vite';

export default defineConfig({
  plugins: [
    Info({ settings: 'config.yml' })
  ]
});

Finally, in your app:

import { field1, field2 } from '~build/settings'

Additional context

No response

@yjl9903 yjl9903 added the enhancement New feature or request label Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant