question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`extends` in `defineConfig`

See original GitHub issue

Description

I’d like to add a field extends for defineConfig like this:

import commonConfig from '@company/vite-config-common'

export default defineConfig({
  extends: [commonConfig]
})

It would help us unify and simplify the vite config files in our projects.

Suggested solution

The semantics of extends can be identical to mergeConfig. We can allow using package name directly in extends for convenience.

Alternative

  1. mergeConfig Adding extends field is more simple and constrained than letting users use mergeConfig directly in their config files. Besides, mergeConfig is an undocumented API.

  2. abstract over vite defineConfig Wrap around vite like:

// @mycompany/wrapped-vite/index.ts
import { mergeConfig, defineConfig } from 'vite'
const commonConfig = ...
export const defineConfig: typeof defineConfig = (...args) => mergeConfig(commonConfig, defineConfig(...args))

// user-project/vite.config.ts
import { defineConfig } from '@mycompany/wrapped-vite'
export default defineConfig({...})

It works but we think it’s better to add this ability directly to vite rather than wrap it.

Additional context

No response

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
bluwycommented, Jul 14, 2022

mergeConfig and many exposed APIs are always public, but we expose a lot of APIs to fit in the docs so it only shows the commonly used ones. I think using mergeConfig is the way to go here. If we implement extends it’ll very likely be the same as mergeConfig, and it’s better to have one way of doings things. Plus doing it in-code makes it easier to reason how data is passed around.

1reaction
lsdsjycommented, Jul 14, 2022

https://github.com/vitejs/vite/pull/8999 It seems that Vite now documents mergeConfig as an public API. Though I still don’t want users of my common config uses mergeConfig directly, this feature request is more unnecessary now.😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Vite
Configuring Vite #. When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project...
Read more >
How to extend cypress.json config to other configuration files?
Cypress plugin that adds "extends" support to the configuration file. ... const { defineConfig } = require('cypress') const baseConfig ...
Read more >
Writing a Plugin - Cypress Documentation
The Plugins API allows you to hook into and extend Cypress behavior. ... const { defineConfig } = require('cypress') module.exports = defineConfig({ ...
Read more >
Configuring Windi CSS
defineConfig is a bypass function with type hints, which means you can also omit it if you don't need the autocompletion/typecheck. windi.config.js. export ......
Read more >
Configuring Vitest
VITEST or mode property on defineConfig (will be set to test ... When using a separate vitest.config.js , you can also extend Vite's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found