feat(kit): addBuildPlugin for builder-agnostic implementation (#20587)

This commit is contained in:
Daniel Roe 2023-05-14 12:55:26 +01:00 committed by GitHub
parent d077c10c41
commit 7006064567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -136,3 +136,18 @@ export function addVitePlugin (pluginOrGetter: VitePlugin | VitePlugin[] | (() =
}
}, options)
}
interface AddBuildPluginFactory {
vite?: () => VitePlugin | VitePlugin[]
webpack?: () => WebpackPluginInstance | WebpackPluginInstance[]
}
export function addBuildPlugin (pluginFactory: AddBuildPluginFactory, options?: ExtendConfigOptions) {
if (pluginFactory.vite) {
addVitePlugin(pluginFactory.vite, options)
}
if (pluginFactory.webpack) {
addWebpackPlugin(pluginFactory.webpack, options)
}
}

View File

@ -1,4 +1,4 @@
import { addComponent, addVitePlugin, addWebpackPlugin } from 'nuxt/kit'
import { addBuildPlugin, addComponent } from 'nuxt/kit'
import type { NuxtPage } from 'nuxt/schema'
import { createUnplugin } from 'unplugin'
import { withoutLeadingSlash } from 'ufo'
@ -104,8 +104,7 @@ export default defineNuxtConfig({
if (id === 'virtual.css') { return ':root { --virtual: red }' }
}
}))
addVitePlugin(() => plugin.vite())
addWebpackPlugin(() => plugin.webpack())
addBuildPlugin(plugin)
},
function (_options, nuxt) {
const routesToDuplicate = ['/async-parent', '/fixed-keyed-child-parent', '/keyed-child-parent', '/with-layout', '/with-layout2']