mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +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
|
* @default true
|
||||||
*/
|
*/
|
||||||
client?: boolean
|
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 {}
|
export interface ExtendViteConfigOptions extends ExtendConfigOptions {}
|
||||||
|
|
||||||
@ -104,12 +107,13 @@ export function extendViteConfig (
|
|||||||
* Append webpack plugin to the config.
|
* Append webpack plugin to the config.
|
||||||
*/
|
*/
|
||||||
export function addWebpackPlugin (plugin: WebpackPluginInstance | WebpackPluginInstance[], options?: ExtendWebpackConfigOptions) {
|
export function addWebpackPlugin (plugin: WebpackPluginInstance | WebpackPluginInstance[], options?: ExtendWebpackConfigOptions) {
|
||||||
|
const method: 'push' | 'unshift' = options?.prepend ? 'unshift' : 'push'
|
||||||
extendWebpackConfig((config) => {
|
extendWebpackConfig((config) => {
|
||||||
config.plugins = config.plugins || []
|
config.plugins = config.plugins || []
|
||||||
if (Array.isArray(plugin)) {
|
if (Array.isArray(plugin)) {
|
||||||
config.plugins.push(...plugin)
|
config.plugins[method](...plugin)
|
||||||
} else {
|
} else {
|
||||||
config.plugins.push(plugin)
|
config.plugins[method](plugin)
|
||||||
}
|
}
|
||||||
}, options)
|
}, options)
|
||||||
}
|
}
|
||||||
@ -118,12 +122,13 @@ export function addWebpackPlugin (plugin: WebpackPluginInstance | WebpackPluginI
|
|||||||
* Append Vite plugin to the config.
|
* Append Vite plugin to the config.
|
||||||
*/
|
*/
|
||||||
export function addVitePlugin (plugin: VitePlugin | VitePlugin[], options?: ExtendViteConfigOptions) {
|
export function addVitePlugin (plugin: VitePlugin | VitePlugin[], options?: ExtendViteConfigOptions) {
|
||||||
|
const method: 'push' | 'unshift' = options?.prepend ? 'unshift' : 'push'
|
||||||
extendViteConfig((config) => {
|
extendViteConfig((config) => {
|
||||||
config.plugins = config.plugins || []
|
config.plugins = config.plugins || []
|
||||||
if (Array.isArray(plugin)) {
|
if (Array.isArray(plugin)) {
|
||||||
config.plugins.push(...plugin)
|
config.plugins[method](...plugin)
|
||||||
} else {
|
} else {
|
||||||
config.plugins.push(plugin)
|
config.plugins[method](plugin)
|
||||||
}
|
}
|
||||||
}, options)
|
}, options)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user