mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
perf(nuxt): remove pure annotations plugin (#24033)
This commit is contained in:
parent
4f017a5538
commit
27791f4c33
@ -24,7 +24,7 @@ const nuxtApp = useNuxtApp()
|
|||||||
const onResolve = nuxtApp.deferHydration()
|
const onResolve = nuxtApp.deferHydration()
|
||||||
|
|
||||||
const url = import.meta.server ? nuxtApp.ssrContext.url : window.location.pathname
|
const url = import.meta.server ? nuxtApp.ssrContext.url : window.location.pathname
|
||||||
const SingleRenderer = import.meta.test && import.meta.dev && import.meta.server && url.startsWith('/__nuxt_component_test__/') && /* #__PURE__ */ defineAsyncComponent(() => import('#build/test-component-wrapper.mjs')
|
const SingleRenderer = import.meta.test && import.meta.dev && import.meta.server && url.startsWith('/__nuxt_component_test__/') && defineAsyncComponent(() => import('#build/test-component-wrapper.mjs')
|
||||||
.then(r => r.default(import.meta.server ? url : window.location.href)))
|
.then(r => r.default(import.meta.server ? url : window.location.href)))
|
||||||
|
|
||||||
// Inject default route (outside of pages) as active route
|
// Inject default route (outside of pages) as active route
|
||||||
|
@ -74,12 +74,12 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => {
|
|||||||
if (lazy) {
|
if (lazy) {
|
||||||
imports.add(genImport('vue', [{ name: 'defineAsyncComponent', as: '__defineAsyncComponent' }]))
|
imports.add(genImport('vue', [{ name: 'defineAsyncComponent', as: '__defineAsyncComponent' }]))
|
||||||
identifier += '_lazy'
|
identifier += '_lazy'
|
||||||
imports.add(`const ${identifier} = /*#__PURE__*/ __defineAsyncComponent(${genDynamicImport(component.filePath, { interopDefault: true })}${isClientOnly ? '.then(c => createClientOnly(c))' : ''})`)
|
imports.add(`const ${identifier} = __defineAsyncComponent(${genDynamicImport(component.filePath, { interopDefault: true })}${isClientOnly ? '.then(c => createClientOnly(c))' : ''})`)
|
||||||
} else {
|
} else {
|
||||||
imports.add(genImport(component.filePath, [{ name: component.export, as: identifier }]))
|
imports.add(genImport(component.filePath, [{ name: component.export, as: identifier }]))
|
||||||
|
|
||||||
if (isClientOnly) {
|
if (isClientOnly) {
|
||||||
imports.add(`const ${identifier}_wrapped = /*#__PURE__*/ createClientOnly(${identifier})`)
|
imports.add(`const ${identifier}_wrapped = createClientOnly(${identifier})`)
|
||||||
identifier += '_wrapped'
|
identifier += '_wrapped'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { defineComponent, h } from 'vue'
|
import { defineComponent, h } from 'vue'
|
||||||
import NuxtIsland from '#app/components/nuxt-island'
|
import NuxtIsland from '#app/components/nuxt-island'
|
||||||
|
|
||||||
|
/*! @__NO_SIDE_EFFECTS__ */
|
||||||
export const createServerComponent = (name: string) => {
|
export const createServerComponent = (name: string) => {
|
||||||
return defineComponent({
|
return defineComponent({
|
||||||
name,
|
name,
|
||||||
|
@ -90,7 +90,7 @@ export const componentsIslandsTemplate: NuxtTemplate<ComponentsTemplateContext>
|
|||||||
(c) => {
|
(c) => {
|
||||||
const exp = c.export === 'default' ? 'c.default || c' : `c['${c.export}']`
|
const exp = c.export === 'default' ? 'c.default || c' : `c['${c.export}']`
|
||||||
const comment = createImportMagicComments(c)
|
const comment = createImportMagicComments(c)
|
||||||
return `export const ${c.pascalName} = /* #__PURE__ */ defineAsyncComponent(${genDynamicImport(c.filePath, { comment })}.then(c => ${exp}))`
|
return `export const ${c.pascalName} = defineAsyncComponent(${genDynamicImport(c.filePath, { comment })}.then(c => ${exp}))`
|
||||||
}
|
}
|
||||||
)].join('\n')
|
)].join('\n')
|
||||||
}
|
}
|
||||||
|
@ -76,5 +76,6 @@ export const definePageMeta = (meta: PageMeta): void => {
|
|||||||
* For more control, such as if you are using a custom `path` or `alias` set in the page's `definePageMeta`, you
|
* For more control, such as if you are using a custom `path` or `alias` set in the page's `definePageMeta`, you
|
||||||
* should set `routeRules` directly within your `nuxt.config`.
|
* should set `routeRules` directly within your `nuxt.config`.
|
||||||
*/
|
*/
|
||||||
|
/*! @__NO_SIDE_EFFECTS__ */
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
export const defineRouteRules = (rules: NitroRouteConfig): void => {}
|
export const defineRouteRules = (rules: NitroRouteConfig): void => {}
|
||||||
|
@ -15,7 +15,6 @@ import type { ViteBuildContext } from './vite'
|
|||||||
import { devStyleSSRPlugin } from './plugins/dev-ssr-css'
|
import { devStyleSSRPlugin } from './plugins/dev-ssr-css'
|
||||||
import { runtimePathsPlugin } from './plugins/paths'
|
import { runtimePathsPlugin } from './plugins/paths'
|
||||||
import { typeCheckPlugin } from './plugins/type-check'
|
import { typeCheckPlugin } from './plugins/type-check'
|
||||||
import { pureAnnotationsPlugin } from './plugins/pure-annotations'
|
|
||||||
import { viteNodePlugin } from './vite-node'
|
import { viteNodePlugin } from './vite-node'
|
||||||
import { createViteLogger } from './utils/logger'
|
import { createViteLogger } from './utils/logger'
|
||||||
|
|
||||||
@ -80,11 +79,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
runtimePathsPlugin({
|
runtimePathsPlugin({
|
||||||
sourcemap: !!ctx.nuxt.options.sourcemap.client
|
sourcemap: !!ctx.nuxt.options.sourcemap.client
|
||||||
}),
|
}),
|
||||||
viteNodePlugin(ctx),
|
viteNodePlugin(ctx)
|
||||||
pureAnnotationsPlugin.vite({
|
|
||||||
sourcemap: !!ctx.nuxt.options.sourcemap.client,
|
|
||||||
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig', 'defineRouteRules']
|
|
||||||
})
|
|
||||||
],
|
],
|
||||||
appType: 'custom',
|
appType: 'custom',
|
||||||
server: {
|
server: {
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
import MagicString from 'magic-string'
|
|
||||||
import { createUnplugin } from 'unplugin'
|
|
||||||
import { stripLiteral } from 'strip-literal'
|
|
||||||
import { isJS, isVue } from '../../../nuxt/src/core/utils/plugins'
|
|
||||||
|
|
||||||
interface PureAnnotationsOptions {
|
|
||||||
sourcemap: boolean
|
|
||||||
functions: string[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export const pureAnnotationsPlugin = createUnplugin((options: PureAnnotationsOptions) => {
|
|
||||||
const FUNCTION_RE = new RegExp(`(?<!\\/\\* #__PURE__ \\*\\/ )\\b(${options.functions.join('|')})\\s*\\(`, 'g')
|
|
||||||
const FUNCTION_RE_SINGLE = new RegExp(`(?<!\\/\\* #__PURE__ \\*\\/ )\\b(${options.functions.join('|')})\\s*\\(`)
|
|
||||||
return {
|
|
||||||
name: 'nuxt:pure-annotations',
|
|
||||||
enforce: 'post',
|
|
||||||
transformInclude (id) {
|
|
||||||
return isVue(id, { type: ['script'] }) || isJS(id)
|
|
||||||
},
|
|
||||||
transform (code) {
|
|
||||||
if (!FUNCTION_RE_SINGLE.test(code)) { return }
|
|
||||||
|
|
||||||
const s = new MagicString(code)
|
|
||||||
const strippedCode = stripLiteral(code)
|
|
||||||
|
|
||||||
for (const match of strippedCode.matchAll(FUNCTION_RE)) {
|
|
||||||
s.overwrite(match.index!, match.index! + match[0].length, '/* #__PURE__ */ ' + match[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s.hasChanged()) {
|
|
||||||
return {
|
|
||||||
code: s.toString(),
|
|
||||||
map: options.sourcemap
|
|
||||||
? s.generateMap({ hires: true })
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
@ -8,7 +8,6 @@ import type { ViteConfig } from '@nuxt/schema'
|
|||||||
import type { ViteBuildContext } from './vite'
|
import type { ViteBuildContext } from './vite'
|
||||||
import { createViteLogger } from './utils/logger'
|
import { createViteLogger } from './utils/logger'
|
||||||
import { initViteNodeServer } from './vite-node'
|
import { initViteNodeServer } from './vite-node'
|
||||||
import { pureAnnotationsPlugin } from './plugins/pure-annotations'
|
|
||||||
import { writeManifest } from './manifest'
|
import { writeManifest } from './manifest'
|
||||||
import { transpile } from './utils/transpile'
|
import { transpile } from './utils/transpile'
|
||||||
|
|
||||||
@ -101,12 +100,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
preTransformRequests: false,
|
preTransformRequests: false,
|
||||||
hmr: false
|
hmr: false
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: []
|
||||||
pureAnnotationsPlugin.vite({
|
|
||||||
sourcemap: !!ctx.nuxt.options.sourcemap.server,
|
|
||||||
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig', 'defineRouteRules']
|
|
||||||
})
|
|
||||||
]
|
|
||||||
} satisfies vite.InlineConfig, ctx.nuxt.options.vite.$server || {}))
|
} satisfies vite.InlineConfig, ctx.nuxt.options.vite.$server || {}))
|
||||||
|
|
||||||
if (!ctx.nuxt.options.dev) {
|
if (!ctx.nuxt.options.dev) {
|
||||||
|
Loading…
Reference in New Issue
Block a user