mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
feat(kit): addBuildPlugin
for builder-agnostic implementation (#20587)
This commit is contained in:
parent
d077c10c41
commit
7006064567
@ -136,3 +136,18 @@ export function addVitePlugin (pluginOrGetter: VitePlugin | VitePlugin[] | (() =
|
|||||||
}
|
}
|
||||||
}, options)
|
}, 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
5
test/fixtures/basic/nuxt.config.ts
vendored
5
test/fixtures/basic/nuxt.config.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import { addComponent, addVitePlugin, addWebpackPlugin } from 'nuxt/kit'
|
import { addBuildPlugin, addComponent } from 'nuxt/kit'
|
||||||
import type { NuxtPage } from 'nuxt/schema'
|
import type { NuxtPage } from 'nuxt/schema'
|
||||||
import { createUnplugin } from 'unplugin'
|
import { createUnplugin } from 'unplugin'
|
||||||
import { withoutLeadingSlash } from 'ufo'
|
import { withoutLeadingSlash } from 'ufo'
|
||||||
@ -104,8 +104,7 @@ export default defineNuxtConfig({
|
|||||||
if (id === 'virtual.css') { return ':root { --virtual: red }' }
|
if (id === 'virtual.css') { return ':root { --virtual: red }' }
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
addVitePlugin(() => plugin.vite())
|
addBuildPlugin(plugin)
|
||||||
addWebpackPlugin(() => plugin.webpack())
|
|
||||||
},
|
},
|
||||||
function (_options, nuxt) {
|
function (_options, nuxt) {
|
||||||
const routesToDuplicate = ['/async-parent', '/fixed-keyed-child-parent', '/keyed-child-parent', '/with-layout', '/with-layout2']
|
const routesToDuplicate = ['/async-parent', '/fixed-keyed-child-parent', '/keyed-child-parent', '/with-layout', '/with-layout2']
|
||||||
|
Loading…
Reference in New Issue
Block a user