mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
perf(vite): mark more core functions as side-effect free (#19508)
This commit is contained in:
parent
0b82f67514
commit
c2ab76d68e
@ -10,7 +10,7 @@ import type { H3Event } from 'h3'
|
|||||||
import type { NuxtIslandContext } from '../core/runtime/nitro/renderer'
|
import type { NuxtIslandContext } from '../core/runtime/nitro/renderer'
|
||||||
import type { RuntimeConfig, AppConfigInput } from 'nuxt/schema'
|
import type { RuntimeConfig, AppConfigInput } from 'nuxt/schema'
|
||||||
|
|
||||||
const nuxtAppCtx = getContext<NuxtApp>('nuxt-app')
|
const nuxtAppCtx = /* #__PURE__ */ getContext<NuxtApp>('nuxt-app')
|
||||||
|
|
||||||
type NuxtMeta = {
|
type NuxtMeta = {
|
||||||
htmlAttrs?: string
|
htmlAttrs?: string
|
||||||
|
@ -218,7 +218,7 @@ const inlineConfig = ${JSON.stringify(nuxt.options.appConfig, null, 2)}
|
|||||||
|
|
||||||
${app.configs.map((id: string, index: number) => `import ${`cfg${index}`} from ${JSON.stringify(id)}`).join('\n')}
|
${app.configs.map((id: string, index: number) => `import ${`cfg${index}`} from ${JSON.stringify(id)}`).join('\n')}
|
||||||
|
|
||||||
export default defuFn(${app.configs.map((_id: string, index: number) => `cfg${index}`).concat(['inlineConfig']).join(', ')})
|
export default /* #__PURE__ */ defuFn(${app.configs.map((_id: string, index: number) => `cfg${index}`).concat(['inlineConfig']).join(', ')})
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
viteNodePlugin(ctx),
|
viteNodePlugin(ctx),
|
||||||
pureAnnotationsPlugin.vite({
|
pureAnnotationsPlugin.vite({
|
||||||
sourcemap: ctx.nuxt.options.sourcemap.client,
|
sourcemap: ctx.nuxt.options.sourcemap.client,
|
||||||
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly']
|
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig']
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
appType: 'custom',
|
appType: 'custom',
|
||||||
|
@ -114,7 +114,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
viteJsxPlugin(ctx.config.vueJsx),
|
viteJsxPlugin(ctx.config.vueJsx),
|
||||||
pureAnnotationsPlugin.vite({
|
pureAnnotationsPlugin.vite({
|
||||||
sourcemap: ctx.nuxt.options.sourcemap.server,
|
sourcemap: ctx.nuxt.options.sourcemap.server,
|
||||||
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly']
|
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig']
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
} as ViteOptions)
|
} as ViteOptions)
|
||||||
|
@ -26,7 +26,7 @@ describe.skipIf(isWindows)('minimal nuxt application', () => {
|
|||||||
|
|
||||||
it('default client bundle size', async () => {
|
it('default client bundle size', async () => {
|
||||||
stats.client = await analyzeSizes('**/*.js', publicDir)
|
stats.client = await analyzeSizes('**/*.js', publicDir)
|
||||||
expect(stats.client.totalBytes).toBeLessThan(108000)
|
expect(stats.client.totalBytes).toBeLessThan(106000)
|
||||||
expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
|
expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
"_nuxt/_plugin-vue_export-helper.js",
|
"_nuxt/_plugin-vue_export-helper.js",
|
||||||
@ -40,7 +40,7 @@ describe.skipIf(isWindows)('minimal nuxt application', () => {
|
|||||||
|
|
||||||
it('default server bundle size', async () => {
|
it('default server bundle size', async () => {
|
||||||
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
|
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
|
||||||
expect(stats.server.totalBytes).toBeLessThan(94000)
|
expect(stats.server.totalBytes).toBeLessThan(93000)
|
||||||
|
|
||||||
const modules = await analyzeSizes('node_modules/**/*', serverDir)
|
const modules = await analyzeSizes('node_modules/**/*', serverDir)
|
||||||
expect(modules.totalBytes).toBeLessThan(2722000)
|
expect(modules.totalBytes).toBeLessThan(2722000)
|
||||||
|
Loading…
Reference in New Issue
Block a user