mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feat(kit): allow vite and webpack plugins to be prepended (#20403)
Co-authored-by: Eduardo San Martin Morote <posva13@gmail.com>
This commit is contained in:
parent
6ef2e1caea
commit
b2a1f9f339
@ -27,10 +27,13 @@ export interface ExtendConfigOptions {
|
||||
* @default true
|
||||
*/
|
||||
client?: boolean
|
||||
/**
|
||||
* Prepends the plugin to the array with `unshit()` instead of `push()`.
|
||||
*/
|
||||
prepend?: boolean
|
||||
}
|
||||
|
||||
export interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
|
||||
}
|
||||
export interface ExtendWebpackConfigOptions extends ExtendConfigOptions {}
|
||||
|
||||
export interface ExtendViteConfigOptions extends ExtendConfigOptions {}
|
||||
|
||||
@ -104,12 +107,13 @@ export function extendViteConfig (
|
||||
* Append webpack plugin to the config.
|
||||
*/
|
||||
export function addWebpackPlugin (plugin: WebpackPluginInstance | WebpackPluginInstance[], options?: ExtendWebpackConfigOptions) {
|
||||
const method: 'push' | 'unshift' = options?.prepend ? 'unshift' : 'push'
|
||||
extendWebpackConfig((config) => {
|
||||
config.plugins = config.plugins || []
|
||||
if (Array.isArray(plugin)) {
|
||||
config.plugins.push(...plugin)
|
||||
config.plugins[method](...plugin)
|
||||
} else {
|
||||
config.plugins.push(plugin)
|
||||
config.plugins[method](plugin)
|
||||
}
|
||||
}, options)
|
||||
}
|
||||
@ -118,12 +122,13 @@ export function addWebpackPlugin (plugin: WebpackPluginInstance | WebpackPluginI
|
||||
* Append Vite plugin to the config.
|
||||
*/
|
||||
export function addVitePlugin (plugin: VitePlugin | VitePlugin[], options?: ExtendViteConfigOptions) {
|
||||
const method: 'push' | 'unshift' = options?.prepend ? 'unshift' : 'push'
|
||||
extendViteConfig((config) => {
|
||||
config.plugins = config.plugins || []
|
||||
if (Array.isArray(plugin)) {
|
||||
config.plugins.push(...plugin)
|
||||
config.plugins[method](...plugin)
|
||||
} else {
|
||||
config.plugins.push(plugin)
|
||||
config.plugins[method](plugin)
|
||||
}
|
||||
}, options)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user