mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 00:23:53 +00:00
perf(nuxt): mark define functions as side-effect free at source (#21434)
This commit is contained in:
parent
2fccfa2d5c
commit
6d59a027c7
@ -94,7 +94,10 @@
|
||||
"varsIgnorePattern": "^_",
|
||||
"ignoreRestSiblings": true
|
||||
}
|
||||
]
|
||||
],
|
||||
"jsdoc/check-tag-names": ["error", {
|
||||
"definedTags": ["__NO_SIDE_EFFECTS__"]
|
||||
}]
|
||||
},
|
||||
"settings": {
|
||||
"jsdoc": {
|
||||
|
@ -22,6 +22,7 @@ export default defineComponent({
|
||||
|
||||
const cache = new WeakMap()
|
||||
|
||||
/*! @__NO_SIDE_EFFECTS__ */
|
||||
export function createClientOnly<T extends ComponentOptions> (component: T) {
|
||||
if (cache.has(component)) {
|
||||
return cache.get(component)
|
||||
|
@ -46,6 +46,7 @@ export type NuxtLinkProps = {
|
||||
ariaCurrentValue?: string
|
||||
}
|
||||
|
||||
/*! @__NO_SIDE_EFFECTS__ */
|
||||
export function defineNuxtLink (options: NuxtLinkOptions) {
|
||||
const componentName = options.componentName || 'NuxtLink'
|
||||
|
||||
|
@ -27,6 +27,7 @@ async function runLegacyAsyncData (res: Record<string, any> | Promise<Record<str
|
||||
}
|
||||
}
|
||||
|
||||
/*! @__NO_SIDE_EFFECTS__ */
|
||||
export const defineNuxtComponent: typeof defineComponent =
|
||||
function defineNuxtComponent (...args: any[]): any {
|
||||
const [options, key] = args
|
||||
|
@ -42,7 +42,10 @@ export interface RouteMiddleware {
|
||||
(to: RouteLocationNormalized, from: RouteLocationNormalized): ReturnType<NavigationGuard>
|
||||
}
|
||||
|
||||
export const defineNuxtRouteMiddleware = (middleware: RouteMiddleware) => middleware
|
||||
/*! @__NO_SIDE_EFFECTS__ */
|
||||
export function defineNuxtRouteMiddleware (middleware: RouteMiddleware) {
|
||||
return middleware
|
||||
}
|
||||
|
||||
export interface AddRouteMiddlewareOptions {
|
||||
global?: boolean
|
||||
|
@ -381,10 +381,12 @@ const orderMap: Record<NonNullable<ObjectPluginInput['enforce']>, number> = {
|
||||
post: 20
|
||||
}
|
||||
|
||||
/*! @__NO_SIDE_EFFECTS__ */
|
||||
export function definePayloadPlugin<T extends Record<string, unknown>> (plugin: Plugin<T> | ObjectPluginInput<T>) {
|
||||
return defineNuxtPlugin(plugin, { order: -40 })
|
||||
}
|
||||
|
||||
/*! @__NO_SIDE_EFFECTS__ */
|
||||
export function defineNuxtPlugin<T extends Record<string, unknown>> (plugin: Plugin<T> | ObjectPluginInput<T>, meta?: PluginMeta): Plugin<T> {
|
||||
if (typeof plugin === 'function') { return defineNuxtPlugin({ setup: plugin }, meta) }
|
||||
|
||||
@ -433,6 +435,7 @@ export function callWithNuxt<T extends (...args: any[]) => any> (nuxt: NuxtApp |
|
||||
}
|
||||
}
|
||||
|
||||
/*! @__NO_SIDE_EFFECTS__ */
|
||||
/**
|
||||
* Returns the current Nuxt instance.
|
||||
*/
|
||||
@ -455,6 +458,7 @@ export function useNuxtApp (): NuxtApp {
|
||||
return nuxtAppInstance
|
||||
}
|
||||
|
||||
/*! @__NO_SIDE_EFFECTS__ */
|
||||
export function useRuntimeConfig (): RuntimeConfig {
|
||||
return useNuxtApp().$config
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e
|
||||
|
||||
it('default server bundle size', async () => {
|
||||
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
|
||||
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"62.5k"')
|
||||
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"62.6k"')
|
||||
|
||||
const modules = await analyzeSizes('node_modules/**/*', serverDir)
|
||||
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2284k"')
|
||||
|
Loading…
Reference in New Issue
Block a user