mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
feat(nuxt): environment-specific plugin execution for islands (#20726)
This commit is contained in:
parent
ffc4e798cd
commit
0f839dd723
@ -155,6 +155,16 @@ export interface PluginMeta {
|
||||
order?: number
|
||||
}
|
||||
|
||||
export interface PluginEnvContext {
|
||||
/**
|
||||
* This enable the plugin for islands components.
|
||||
* Require `experimental.componentsIslands`.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
islands?: boolean
|
||||
}
|
||||
|
||||
export interface ResolvedPluginMeta {
|
||||
name?: string
|
||||
parallel?: boolean
|
||||
@ -169,6 +179,7 @@ export interface Plugin<Injections extends Record<string, unknown> = Record<stri
|
||||
export interface ObjectPlugin<Injections extends Record<string, unknown> = Record<string, unknown>> extends PluginMeta {
|
||||
hooks?: Partial<RuntimeNuxtHooks>
|
||||
setup?: Plugin<Injections>
|
||||
env?: PluginEnvContext
|
||||
/**
|
||||
* Execute plugin in parallel with other parallel plugins.
|
||||
*
|
||||
@ -318,6 +329,7 @@ export async function applyPlugins (nuxtApp: NuxtApp, plugins: Array<Plugin & Ob
|
||||
const parallels: Promise<any>[] = []
|
||||
const errors: Error[] = []
|
||||
for (const plugin of plugins) {
|
||||
if (process.server && nuxtApp.ssrContext?.islandContext && plugin.env?.islands === false) { continue }
|
||||
const promise = applyPlugin(nuxtApp, plugin)
|
||||
if (plugin.parallel) {
|
||||
parallels.push(promise.catch(e => errors.push(e)))
|
||||
|
@ -32,7 +32,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
|
||||
const serverDir = join(rootDir, '.output/server')
|
||||
|
||||
const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
|
||||
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"64.2k"')
|
||||
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"64.4k"')
|
||||
|
||||
const modules = await analyzeSizes('node_modules/**/*', serverDir)
|
||||
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2330k"')
|
||||
|
@ -8,6 +8,7 @@
|
||||
<div id="long-async-component-count">
|
||||
{{ count }}
|
||||
</div>
|
||||
{{ headers['custom-head'] }}
|
||||
<slot name="test" :count="count" />
|
||||
<p>hello world !!!</p>
|
||||
<slot v-for="(t, index) in 3" name="hello" :t="t">
|
||||
@ -28,8 +29,12 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getResponseHeaders } from 'h3'
|
||||
defineProps<{
|
||||
count: number
|
||||
}>()
|
||||
|
||||
const evt = useRequestEvent()
|
||||
const headers = getResponseHeaders(evt)
|
||||
const { data } = await useFetch('/api/very-long-request')
|
||||
</script>
|
||||
|
12
test/fixtures/basic/plugins/server-only.server.ts
vendored
Normal file
12
test/fixtures/basic/plugins/server-only.server.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { setHeader } from 'h3'
|
||||
|
||||
export default defineNuxtPlugin({
|
||||
name: 'server-only-plugin',
|
||||
setup () {
|
||||
const evt = useRequestEvent()
|
||||
setHeader(evt, 'custom-head', 'hello')
|
||||
},
|
||||
env: {
|
||||
islands: false
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user