mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +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": "^_",
|
"varsIgnorePattern": "^_",
|
||||||
"ignoreRestSiblings": true
|
"ignoreRestSiblings": true
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"jsdoc/check-tag-names": ["error", {
|
||||||
|
"definedTags": ["__NO_SIDE_EFFECTS__"]
|
||||||
|
}]
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"jsdoc": {
|
"jsdoc": {
|
||||||
|
@ -22,6 +22,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
const cache = new WeakMap()
|
const cache = new WeakMap()
|
||||||
|
|
||||||
|
/*! @__NO_SIDE_EFFECTS__ */
|
||||||
export function createClientOnly<T extends ComponentOptions> (component: T) {
|
export function createClientOnly<T extends ComponentOptions> (component: T) {
|
||||||
if (cache.has(component)) {
|
if (cache.has(component)) {
|
||||||
return cache.get(component)
|
return cache.get(component)
|
||||||
|
@ -46,6 +46,7 @@ export type NuxtLinkProps = {
|
|||||||
ariaCurrentValue?: string
|
ariaCurrentValue?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! @__NO_SIDE_EFFECTS__ */
|
||||||
export function defineNuxtLink (options: NuxtLinkOptions) {
|
export function defineNuxtLink (options: NuxtLinkOptions) {
|
||||||
const componentName = options.componentName || 'NuxtLink'
|
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 =
|
export const defineNuxtComponent: typeof defineComponent =
|
||||||
function defineNuxtComponent (...args: any[]): any {
|
function defineNuxtComponent (...args: any[]): any {
|
||||||
const [options, key] = args
|
const [options, key] = args
|
||||||
|
@ -42,7 +42,10 @@ export interface RouteMiddleware {
|
|||||||
(to: RouteLocationNormalized, from: RouteLocationNormalized): ReturnType<NavigationGuard>
|
(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 {
|
export interface AddRouteMiddlewareOptions {
|
||||||
global?: boolean
|
global?: boolean
|
||||||
|
@ -381,10 +381,12 @@ const orderMap: Record<NonNullable<ObjectPluginInput['enforce']>, number> = {
|
|||||||
post: 20
|
post: 20
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! @__NO_SIDE_EFFECTS__ */
|
||||||
export function definePayloadPlugin<T extends Record<string, unknown>> (plugin: Plugin<T> | ObjectPluginInput<T>) {
|
export function definePayloadPlugin<T extends Record<string, unknown>> (plugin: Plugin<T> | ObjectPluginInput<T>) {
|
||||||
return defineNuxtPlugin(plugin, { order: -40 })
|
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> {
|
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) }
|
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.
|
* Returns the current Nuxt instance.
|
||||||
*/
|
*/
|
||||||
@ -455,6 +458,7 @@ export function useNuxtApp (): NuxtApp {
|
|||||||
return nuxtAppInstance
|
return nuxtAppInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! @__NO_SIDE_EFFECTS__ */
|
||||||
export function useRuntimeConfig (): RuntimeConfig {
|
export function useRuntimeConfig (): RuntimeConfig {
|
||||||
return useNuxtApp().$config
|
return useNuxtApp().$config
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e
|
|||||||
|
|
||||||
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(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"62.5k"')
|
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"62.6k"')
|
||||||
|
|
||||||
const modules = await analyzeSizes('node_modules/**/*', serverDir)
|
const modules = await analyzeSizes('node_modules/**/*', serverDir)
|
||||||
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2284k"')
|
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2284k"')
|
||||||
|
Loading…
Reference in New Issue
Block a user