mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-18 06:31:27 +00:00
Revert "perf: more regex (and related areas) deallocation"
This reverts commit 0a0ec349a1
.
This commit is contained in:
parent
0a0ec349a1
commit
980ebb0fbe
@ -21,6 +21,9 @@ function compareDirByPathLength ({ path: pathA }: { path: string }, { path: path
|
||||
return pathB.split(SLASH_SEPARATOR_RE).filter(Boolean).length - pathA.split(SLASH_SEPARATOR_RE).filter(Boolean).length
|
||||
}
|
||||
|
||||
const DEFAULT_COMPONENTS_DIRS_RE = /\/components(?:\/(?:global|islands))?$/
|
||||
const STARTER_DOT_RE = /^\./g
|
||||
|
||||
export type getComponentsT = (mode?: 'client' | 'server' | 'all') => Component[]
|
||||
|
||||
export default defineNuxtModule<ComponentsOptions>({
|
||||
@ -75,8 +78,6 @@ export default defineNuxtModule<ComponentsOptions>({
|
||||
}))
|
||||
}
|
||||
|
||||
const DEFAULT_COMPONENTS_DIRS_RE = /\/components(?:\/(?:global|islands))?$/
|
||||
const STARTER_DOT_RE = /^\./g
|
||||
// Resolve dirs
|
||||
nuxt.hook('app:resolve', async () => {
|
||||
// components/ dirs from all layers
|
||||
|
@ -24,8 +24,6 @@ interface ComponentChunkOptions {
|
||||
buildDir: string
|
||||
}
|
||||
|
||||
export const IslandsTransformPlugin = (options: ServerOnlyComponentTransformPluginOptions) => createUnplugin((_options, meta) => {
|
||||
const isVite = meta.framework === 'vite'
|
||||
const SCRIPT_RE = /<script[^>]*>/gi
|
||||
const HAS_SLOT_OR_CLIENT_RE = /<slot[^>]*>|nuxt-client/
|
||||
const TEMPLATE_RE = /<template>([\s\S]*)<\/template>/
|
||||
@ -38,6 +36,8 @@ export const IslandsTransformPlugin = (options: ServerOnlyComponentTransformPlug
|
||||
return `<div v-for="${vfor}" style="display: contents;">${code}</div>`
|
||||
}
|
||||
|
||||
export const IslandsTransformPlugin = (options: ServerOnlyComponentTransformPluginOptions) => createUnplugin((_options, meta) => {
|
||||
const isVite = meta.framework === 'vite'
|
||||
return {
|
||||
name: 'nuxt:server-only-component-transform',
|
||||
enforce: 'pre',
|
||||
|
@ -15,12 +15,108 @@ interface TreeShakeTemplatePluginOptions {
|
||||
|
||||
type AcornNode<N extends Node> = N & { start: number, end: number }
|
||||
|
||||
export const TreeShakeTemplatePlugin = (options: TreeShakeTemplatePluginOptions) => createUnplugin(() => {
|
||||
const SSR_RENDER_RE = /ssrRenderComponent/
|
||||
const PLACEHOLDER_EXACT_RE = /^(?:fallback|placeholder)$/
|
||||
const CLIENT_ONLY_NAME_RE = /^(?:_unref\()?(?:_component_)?(?:Lazy|lazy_)?(?:client_only|ClientOnly\)?)$/
|
||||
const PARSER_OPTIONS = { sourceType: 'module', ecmaVersion: 'latest' }
|
||||
|
||||
export const TreeShakeTemplatePlugin = (options: TreeShakeTemplatePluginOptions) => createUnplugin(() => {
|
||||
const regexpMap = new WeakMap<Component[], [RegExp, RegExp, string[]]>()
|
||||
return {
|
||||
name: 'nuxt:tree-shake-template',
|
||||
enforce: 'post',
|
||||
transformInclude (id) {
|
||||
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href))
|
||||
return pathname.endsWith('.vue')
|
||||
},
|
||||
transform (code) {
|
||||
const components = options.getComponents()
|
||||
|
||||
if (!regexpMap.has(components)) {
|
||||
const serverPlaceholderPath = resolve(distDir, 'app/components/server-placeholder')
|
||||
const clientOnlyComponents = components
|
||||
.filter(c => c.mode === 'client' && !components.some(other => other.mode !== 'client' && other.pascalName === c.pascalName && !other.filePath.startsWith(serverPlaceholderPath)))
|
||||
.flatMap(c => [c.pascalName, c.kebabName.replaceAll('-', '_')])
|
||||
.concat(['ClientOnly', 'client_only'])
|
||||
|
||||
regexpMap.set(components, [new RegExp(`(${clientOnlyComponents.join('|')})`), new RegExp(`^(${clientOnlyComponents.map(c => `(?:(?:_unref\\()?(?:_component_)?(?:Lazy|lazy_)?${c}\\)?)`).join('|')})$`), clientOnlyComponents])
|
||||
}
|
||||
|
||||
const s = new MagicString(code)
|
||||
|
||||
const [COMPONENTS_RE, COMPONENTS_IDENTIFIERS_RE] = regexpMap.get(components)!
|
||||
if (!COMPONENTS_RE.test(code)) { return }
|
||||
|
||||
const codeAst = this.parse(code, PARSER_OPTIONS) as AcornNode<Program>
|
||||
|
||||
const componentsToRemoveSet = new Set<string>()
|
||||
|
||||
// remove client only components or components called in ClientOnly default slot
|
||||
walk(codeAst, {
|
||||
enter: (_node) => {
|
||||
const node = _node as AcornNode<Node>
|
||||
if (isSsrRender(node)) {
|
||||
const [componentCall, _, children] = node.arguments
|
||||
if (!componentCall) { return }
|
||||
|
||||
if (componentCall.type === 'Identifier' || componentCall.type === 'MemberExpression' || componentCall.type === 'CallExpression') {
|
||||
const componentName = getComponentName(node)
|
||||
const isClientComponent = COMPONENTS_IDENTIFIERS_RE.test(componentName)
|
||||
const isClientOnlyComponent = CLIENT_ONLY_NAME_RE.test(componentName)
|
||||
|
||||
if (isClientComponent && children?.type === 'ObjectExpression') {
|
||||
const slotsToRemove = isClientOnlyComponent ? children.properties.filter(prop => prop.type === 'Property' && prop.key.type === 'Identifier' && !PLACEHOLDER_EXACT_RE.test(prop.key.name)) as AcornNode<Property>[] : children.properties as AcornNode<Property>[]
|
||||
|
||||
for (const slot of slotsToRemove) {
|
||||
s.remove(slot.start, slot.end + 1)
|
||||
const removedCode = `({${code.slice(slot.start, slot.end + 1)}})`
|
||||
const currentCodeAst = this.parse(s.toString(), PARSER_OPTIONS) as Node
|
||||
|
||||
walk(this.parse(removedCode, PARSER_OPTIONS) as Node, {
|
||||
enter: (_node) => {
|
||||
const node = _node as AcornNode<CallExpression>
|
||||
if (isSsrRender(node)) {
|
||||
const name = getComponentName(node)
|
||||
|
||||
// detect if the component is called else where
|
||||
const nameToRemove = isComponentNotCalledInSetup(currentCodeAst, name)
|
||||
if (nameToRemove) {
|
||||
componentsToRemoveSet.add(nameToRemove)
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const componentsToRemove = [...componentsToRemoveSet]
|
||||
const removedNodes = new WeakSet<AcornNode<Node>>()
|
||||
|
||||
for (const componentName of componentsToRemove) {
|
||||
// remove import declaration if it exists
|
||||
removeImportDeclaration(codeAst, componentName, s)
|
||||
// remove variable declaration
|
||||
removeVariableDeclarator(codeAst, componentName, s, removedNodes)
|
||||
// remove from setup return statement
|
||||
removeFromSetupReturn(codeAst, componentName, s)
|
||||
}
|
||||
|
||||
if (s.hasChanged()) {
|
||||
return {
|
||||
code: s.toString(),
|
||||
map: options.sourcemap
|
||||
? s.generateMap({ hires: true })
|
||||
: undefined,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* find and remove all property with the name parameter from the setup return statement and the __returned__ object
|
||||
*/
|
||||
@ -200,99 +296,3 @@ export const TreeShakeTemplatePlugin = (options: TreeShakeTemplatePluginOptions)
|
||||
if (matched) { return matched }
|
||||
}
|
||||
}
|
||||
|
||||
const regexpMap = new WeakMap<Component[], [RegExp, RegExp, string[]]>()
|
||||
return {
|
||||
name: 'nuxt:tree-shake-template',
|
||||
enforce: 'post',
|
||||
transformInclude (id) {
|
||||
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href))
|
||||
return pathname.endsWith('.vue')
|
||||
},
|
||||
transform (code) {
|
||||
const components = options.getComponents()
|
||||
|
||||
if (!regexpMap.has(components)) {
|
||||
const serverPlaceholderPath = resolve(distDir, 'app/components/server-placeholder')
|
||||
const clientOnlyComponents = components
|
||||
.filter(c => c.mode === 'client' && !components.some(other => other.mode !== 'client' && other.pascalName === c.pascalName && !other.filePath.startsWith(serverPlaceholderPath)))
|
||||
.flatMap(c => [c.pascalName, c.kebabName.replaceAll('-', '_')])
|
||||
.concat(['ClientOnly', 'client_only'])
|
||||
|
||||
regexpMap.set(components, [new RegExp(`(${clientOnlyComponents.join('|')})`), new RegExp(`^(${clientOnlyComponents.map(c => `(?:(?:_unref\\()?(?:_component_)?(?:Lazy|lazy_)?${c}\\)?)`).join('|')})$`), clientOnlyComponents])
|
||||
}
|
||||
|
||||
const s = new MagicString(code)
|
||||
|
||||
const [COMPONENTS_RE, COMPONENTS_IDENTIFIERS_RE] = regexpMap.get(components)!
|
||||
if (!COMPONENTS_RE.test(code)) { return }
|
||||
|
||||
const codeAst = this.parse(code, PARSER_OPTIONS) as AcornNode<Program>
|
||||
|
||||
const componentsToRemoveSet = new Set<string>()
|
||||
|
||||
// remove client only components or components called in ClientOnly default slot
|
||||
walk(codeAst, {
|
||||
enter: (_node) => {
|
||||
const node = _node as AcornNode<Node>
|
||||
if (isSsrRender(node)) {
|
||||
const [componentCall, _, children] = node.arguments
|
||||
if (!componentCall) { return }
|
||||
|
||||
if (componentCall.type === 'Identifier' || componentCall.type === 'MemberExpression' || componentCall.type === 'CallExpression') {
|
||||
const componentName = getComponentName(node)
|
||||
const isClientComponent = COMPONENTS_IDENTIFIERS_RE.test(componentName)
|
||||
const isClientOnlyComponent = CLIENT_ONLY_NAME_RE.test(componentName)
|
||||
|
||||
if (isClientComponent && children?.type === 'ObjectExpression') {
|
||||
const slotsToRemove = isClientOnlyComponent ? children.properties.filter(prop => prop.type === 'Property' && prop.key.type === 'Identifier' && !PLACEHOLDER_EXACT_RE.test(prop.key.name)) as AcornNode<Property>[] : children.properties as AcornNode<Property>[]
|
||||
|
||||
for (const slot of slotsToRemove) {
|
||||
s.remove(slot.start, slot.end + 1)
|
||||
const removedCode = `({${code.slice(slot.start, slot.end + 1)}})`
|
||||
const currentCodeAst = this.parse(s.toString(), PARSER_OPTIONS) as Node
|
||||
|
||||
walk(this.parse(removedCode, PARSER_OPTIONS) as Node, {
|
||||
enter: (_node) => {
|
||||
const node = _node as AcornNode<CallExpression>
|
||||
if (isSsrRender(node)) {
|
||||
const name = getComponentName(node)
|
||||
|
||||
// detect if the component is called else where
|
||||
const nameToRemove = isComponentNotCalledInSetup(currentCodeAst, name)
|
||||
if (nameToRemove) {
|
||||
componentsToRemoveSet.add(nameToRemove)
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const componentsToRemove = [...componentsToRemoveSet]
|
||||
const removedNodes = new WeakSet<AcornNode<Node>>()
|
||||
|
||||
for (const componentName of componentsToRemove) {
|
||||
// remove import declaration if it exists
|
||||
removeImportDeclaration(codeAst, componentName, s)
|
||||
// remove variable declaration
|
||||
removeVariableDeclarator(codeAst, componentName, s, removedNodes)
|
||||
// remove from setup return statement
|
||||
removeFromSetupReturn(codeAst, componentName, s)
|
||||
}
|
||||
|
||||
if (s.hasChanged()) {
|
||||
return {
|
||||
code: s.toString(),
|
||||
map: options.sourcemap
|
||||
? s.generateMap({ hires: true })
|
||||
: undefined,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
|
@ -8,6 +8,10 @@ import type { Component, ComponentsDir } from 'nuxt/schema'
|
||||
|
||||
import { QUOTE_RE, resolveComponentNameSegments } from '../core/utils'
|
||||
|
||||
const ISLAND_RE = /\.island(?:\.global)?$/
|
||||
const GLOBAL_RE = /\.global(?:\.island)?$/
|
||||
const COMPONENT_MODE_RE = /(?<=\.)(client|server)(\.global|\.island)*$/
|
||||
const MODE_REPLACEMENT_RE = /(\.(client|server))?(\.global|\.island)*$/
|
||||
/**
|
||||
* Scan the components inside different components folders
|
||||
* and return a unique list of components
|
||||
@ -25,11 +29,6 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr
|
||||
// All scanned paths
|
||||
const scannedPaths: string[] = []
|
||||
|
||||
const ISLAND_RE = /\.island(?:\.global)?$/
|
||||
const GLOBAL_RE = /\.global(?:\.island)?$/
|
||||
const COMPONENT_MODE_RE = /(?<=\.)(client|server)(\.global|\.island)*$/
|
||||
const MODE_REPLACEMENT_RE = /(\.(client|server))?(\.global|\.island)*$/
|
||||
|
||||
for (const dir of dirs) {
|
||||
if (dir.enabled === false) {
|
||||
continue
|
||||
|
@ -102,10 +102,10 @@ export const componentsIslandsTemplate: NuxtTemplate = {
|
||||
},
|
||||
}
|
||||
|
||||
const NON_VUE_RE = /\b\.(?!vue)\w+$/g
|
||||
export const componentsTypeTemplate = {
|
||||
filename: 'components.d.ts' as const,
|
||||
getContents: ({ app, nuxt }) => {
|
||||
const NON_VUE_RE = /\b\.(?!vue)\w+$/g
|
||||
const buildDir = nuxt.options.buildDir
|
||||
const componentTypes = app.components.filter(c => !c.island).map((c) => {
|
||||
const type = `typeof ${genDynamicImport(isAbsolute(c.filePath)
|
||||
|
@ -10,8 +10,8 @@ import { generateApp as _generateApp, createApp } from './app'
|
||||
import { checkForExternalConfigurationFiles } from './external-config-files'
|
||||
import { cleanupCaches, getVueHash } from './cache'
|
||||
|
||||
export async function build (nuxt: Nuxt) {
|
||||
const IS_RESTART_PATH_RE = /^(?:app\.|error\.|plugins\/|middleware\/|layouts\/)/i
|
||||
export async function build (nuxt: Nuxt) {
|
||||
const app = createApp(nuxt)
|
||||
nuxt.apps.default = app
|
||||
|
||||
|
@ -26,9 +26,9 @@ const logLevelMapReverse = {
|
||||
verbose: 3,
|
||||
} satisfies Record<NuxtOptions['logLevel'], NitroConfig['logLevel']>
|
||||
|
||||
export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
const NODE_MODULES_RE = /(?<=\/)node_modules\/(.+)$/
|
||||
const PNPM_NODE_MODULES_RE = /\.pnpm\/.+\/node_modules\/(.+)$/
|
||||
export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
// Resolve config
|
||||
const excludePaths = nuxt.options._layers
|
||||
.flatMap(l => [
|
||||
|
@ -613,7 +613,7 @@ export default defineNuxtPlugin({
|
||||
})`,
|
||||
})
|
||||
}
|
||||
const RESTART_RE = /^(?:app|error|app\.config)\.(?:js|ts|mjs|jsx|tsx|vue)$/i
|
||||
|
||||
nuxt.hooks.hook('builder:watch', (event, relativePath) => {
|
||||
const path = resolve(nuxt.options.srcDir, relativePath)
|
||||
// Local module patterns
|
||||
@ -791,6 +791,9 @@ async function checkDependencyVersion (name: string, nuxtVersion: string): Promi
|
||||
console.warn(`[nuxt] Expected \`${name}\` to be at least \`${nuxtVersion}\` but got \`${version}\`. This might lead to unexpected behavior. Check your package.json or refresh your lockfile.`)
|
||||
}
|
||||
}
|
||||
|
||||
const RESTART_RE = /^(?:app|error|app\.config)\.(?:js|ts|mjs|jsx|tsx|vue)$/i
|
||||
|
||||
function deduplicateArray<T = unknown> (maybeArray: T): T {
|
||||
if (!Array.isArray(maybeArray)) { return maybeArray }
|
||||
|
||||
|
@ -7,9 +7,10 @@ interface DevOnlyPluginOptions {
|
||||
sourcemap?: boolean
|
||||
}
|
||||
|
||||
export const DevOnlyPlugin = (options: DevOnlyPluginOptions) => createUnplugin(() => {
|
||||
const DEVONLY_COMP_SINGLE_RE = /<(?:dev-only|DevOnly|lazy-dev-only|LazyDevOnly)>[\s\S]*?<\/(?:dev-only|DevOnly|lazy-dev-only|LazyDevOnly)>/
|
||||
const DEVONLY_COMP_RE = /<(?:dev-only|DevOnly|lazy-dev-only|LazyDevOnly)>[\s\S]*?<\/(?:dev-only|DevOnly|lazy-dev-only|LazyDevOnly)>/g
|
||||
|
||||
export const DevOnlyPlugin = (options: DevOnlyPluginOptions) => createUnplugin(() => {
|
||||
return {
|
||||
name: 'nuxt:server-devonly:transform',
|
||||
enforce: 'pre',
|
||||
|
@ -11,6 +11,9 @@ interface LayerAliasingOptions {
|
||||
layers: NuxtConfigLayer[]
|
||||
}
|
||||
|
||||
const ALIAS_RE = /(?<=['"])[~@]{1,2}(?=\/)/g
|
||||
const ALIAS_RE_SINGLE = /(?<=['"])[~@]{1,2}(?=\/)/
|
||||
|
||||
export const LayerAliasingPlugin = (options: LayerAliasingOptions) => createUnplugin((_options, meta) => {
|
||||
const aliases: Record<string, Record<string, string>> = {}
|
||||
for (const layer of options.layers) {
|
||||
@ -24,8 +27,6 @@ export const LayerAliasingPlugin = (options: LayerAliasingOptions) => createUnpl
|
||||
'@@': layer.config?.alias?.['@@'] || rootDir,
|
||||
}
|
||||
}
|
||||
const ALIAS_RE = /(?<=['"])[~@]{1,2}(?=\/)/g
|
||||
const ALIAS_RE_SINGLE = /(?<=['"])[~@]{1,2}(?=\/)/
|
||||
const layers = Object.keys(aliases).sort((a, b) => b.length - a.length)
|
||||
|
||||
return {
|
||||
|
@ -99,13 +99,13 @@ export const serverPluginTemplate: NuxtTemplate = {
|
||||
},
|
||||
}
|
||||
|
||||
export const pluginsDeclaration: NuxtTemplate = {
|
||||
filename: 'types/plugins.d.ts',
|
||||
getContents: async ({ nuxt, app }) => {
|
||||
const TS_RE = /\.[cm]?tsx?$/
|
||||
const JS_LETTER_RE = /\.(?<letter>[cm])?jsx?$/
|
||||
const JS_RE = /\.[cm]jsx?$/
|
||||
const JS_CAPTURE_RE = /\.[cm](jsx?)$/
|
||||
export const pluginsDeclaration: NuxtTemplate = {
|
||||
filename: 'types/plugins.d.ts',
|
||||
getContents: async ({ nuxt, app }) => {
|
||||
const EXTENSION_RE = new RegExp(`(?<=\\w)(${nuxt.options.extensions.map(e => escapeRE(e)).join('|')})$`, 'g')
|
||||
|
||||
const typesDir = join(nuxt.options.buildDir, 'types')
|
||||
@ -177,12 +177,12 @@ export { }
|
||||
},
|
||||
}
|
||||
|
||||
export const schemaTemplate: NuxtTemplate = {
|
||||
filename: 'types/schema.d.ts',
|
||||
getContents: async ({ nuxt }) => {
|
||||
const adHocModules = ['router', 'pages', 'imports', 'meta', 'components', 'nuxt-config-schema']
|
||||
const IMPORT_NAME_RE = /\.\w+$/
|
||||
const GIT_RE = /^git\+/
|
||||
export const schemaTemplate: NuxtTemplate = {
|
||||
filename: 'types/schema.d.ts',
|
||||
getContents: async ({ nuxt }) => {
|
||||
const relativeRoot = relative(resolve(nuxt.options.buildDir, 'types'), nuxt.options.rootDir)
|
||||
const getImportName = (name: string) => (name[0] === '.' ? './' + join(relativeRoot, name) : name).replace(IMPORT_NAME_RE, '')
|
||||
|
||||
@ -528,12 +528,13 @@ export const nuxtConfigTemplate: NuxtTemplate = {
|
||||
},
|
||||
}
|
||||
|
||||
const TYPE_FILENAME_RE = /\.([cm])?[jt]s$/
|
||||
const DECLARATION_RE = /\.d\.[cm]?ts$/
|
||||
export const buildTypeTemplate: NuxtTemplate = {
|
||||
filename: 'types/build.d.ts',
|
||||
getContents ({ app }) {
|
||||
const TYPE_FILENAME_RE = /\.([cm])?[jt]s$/
|
||||
const DECLARATION_RE = /\.d\.[cm]?ts$/
|
||||
let declarations = ''
|
||||
|
||||
for (const file of app.templates) {
|
||||
if (file.write || !file.filename || DECLARATION_RE.test(file.filename)) {
|
||||
continue
|
||||
|
@ -5,9 +5,10 @@ import { tryUseNuxt } from '@nuxt/kit'
|
||||
import type { ImportsOptions } from 'nuxt/schema'
|
||||
import { isJS, isVue } from '../core/utils'
|
||||
|
||||
export const TransformPlugin = ({ ctx, options, sourcemap }: { ctx: Unimport, options: Partial<ImportsOptions>, sourcemap?: boolean }) => createUnplugin(() => {
|
||||
const NODE_MODULES_RE = /[\\/]node_modules[\\/]/
|
||||
const IMPORTS_RE = /(['"])#imports\1/
|
||||
|
||||
export const TransformPlugin = ({ ctx, options, sourcemap }: { ctx: Unimport, options: Partial<ImportsOptions>, sourcemap?: boolean }) => createUnplugin(() => {
|
||||
return {
|
||||
name: 'nuxt:imports-transform',
|
||||
enforce: 'post',
|
||||
|
@ -19,6 +19,8 @@ import { extractRouteRules, getMappedPages } from './route-rules'
|
||||
import { PageMetaPlugin } from './plugins/page-meta'
|
||||
import { RouteInjectionPlugin } from './plugins/route-injection'
|
||||
|
||||
const OPTIONAL_PARAM_RE = /^\/?:.*(?:\?|\(\.\*\)\*)$/
|
||||
|
||||
export default defineNuxtModule({
|
||||
meta: {
|
||||
name: 'pages',
|
||||
@ -289,7 +291,6 @@ export default defineNuxtModule({
|
||||
}
|
||||
})
|
||||
|
||||
const OPTIONAL_PARAM_RE = /^\/?:.*(?:\?|\(\.\*\)\*)$/
|
||||
// Record all pages for use in prerendering
|
||||
const prerenderRoutes = new Set<string>()
|
||||
|
||||
|
@ -15,7 +15,6 @@ interface PageMetaPluginOptions {
|
||||
sourcemap?: boolean
|
||||
}
|
||||
|
||||
export const PageMetaPlugin = (options: PageMetaPluginOptions) => createUnplugin(() => {
|
||||
const HAS_MACRO_RE = /\bdefinePageMeta\s*\(\s*/
|
||||
|
||||
const CODE_EMPTY = `
|
||||
@ -36,28 +35,8 @@ if (import.meta.webpackHot) {
|
||||
if (err) { window.location = window.location.href }
|
||||
})
|
||||
}`
|
||||
// https://github.com/vuejs/vue-loader/pull/1911
|
||||
// https://github.com/vitejs/vite/issues/8473
|
||||
const QUERY_START_RE = /^\?/
|
||||
const MACRO_RE = /¯o=true/
|
||||
function rewriteQuery (id: string) {
|
||||
return id.replace(/\?.+$/, r => '?macro=true&' + r.replace(QUERY_START_RE, '').replace(MACRO_RE, ''))
|
||||
}
|
||||
|
||||
function parseMacroQuery (id: string) {
|
||||
const { search } = parseURL(decodeURIComponent(isAbsolute(id) ? pathToFileURL(id).href : id).replace(/\?macro=true$/, ''))
|
||||
const query = parseQuery(search)
|
||||
if (id.includes('?macro=true')) {
|
||||
return { macro: 'true', ...query }
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
const QUOTED_SPECIFIER_RE = /(["']).*\1/
|
||||
function getQuotedSpecifier (id: string) {
|
||||
return id.match(QUOTED_SPECIFIER_RE)?.[0]
|
||||
}
|
||||
|
||||
export const PageMetaPlugin = (options: PageMetaPluginOptions) => createUnplugin(() => {
|
||||
return {
|
||||
name: 'nuxt:pages-macros-transform',
|
||||
enforce: 'post',
|
||||
@ -194,3 +173,25 @@ if (import.meta.webpackHot) {
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
// https://github.com/vuejs/vue-loader/pull/1911
|
||||
// https://github.com/vitejs/vite/issues/8473
|
||||
const QUERY_START_RE = /^\?/
|
||||
const MACRO_RE = /¯o=true/
|
||||
function rewriteQuery (id: string) {
|
||||
return id.replace(/\?.+$/, r => '?macro=true&' + r.replace(QUERY_START_RE, '').replace(MACRO_RE, ''))
|
||||
}
|
||||
|
||||
function parseMacroQuery (id: string) {
|
||||
const { search } = parseURL(decodeURIComponent(isAbsolute(id) ? pathToFileURL(id).href : id).replace(/\?macro=true$/, ''))
|
||||
const query = parseQuery(search)
|
||||
if (id.includes('?macro=true')) {
|
||||
return { macro: 'true', ...query }
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
const QUOTED_SPECIFIER_RE = /(["']).*\1/
|
||||
function getQuotedSpecifier (id: string) {
|
||||
return id.match(QUOTED_SPECIFIER_RE)?.[0]
|
||||
}
|
||||
|
@ -4,11 +4,12 @@ import type { Nuxt } from '@nuxt/schema'
|
||||
import { stripLiteral } from 'strip-literal'
|
||||
import { isVue } from '../../core/utils'
|
||||
|
||||
export const RouteInjectionPlugin = (nuxt: Nuxt) => createUnplugin(() => {
|
||||
const INJECTION_RE_TEMPLATE = /\b_ctx\.\$route\b/g
|
||||
const INJECTION_RE_SCRIPT = /\bthis\.\$route\b/g
|
||||
|
||||
const INJECTION_SINGLE_RE = /\bthis\.\$route\b|\b_ctx\.\$route\b/
|
||||
|
||||
export const RouteInjectionPlugin = (nuxt: Nuxt) => createUnplugin(() => {
|
||||
return {
|
||||
name: 'nuxt:route-injection-plugin',
|
||||
enforce: 'post',
|
||||
|
@ -17,6 +17,11 @@ interface ComposableKeysOptions {
|
||||
composables: Array<{ name: string, source?: string | RegExp, argumentLength: number }>
|
||||
}
|
||||
|
||||
const stringTypes: Array<string | undefined> = ['Literal', 'TemplateLiteral']
|
||||
const NUXT_LIB_RE = /node_modules\/(?:nuxt|nuxt3|nuxt-nightly)\//
|
||||
const SUPPORTED_EXT_RE = /\.(?:m?[jt]sx?|vue)/
|
||||
const SCRIPT_RE = /(?<=<script[^>]*>)[\s\S]*?(?=<\/script>)/i
|
||||
|
||||
export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptions) => {
|
||||
const composableMeta: Record<string, any> = {}
|
||||
const composableLengths = new Set<number>()
|
||||
@ -30,10 +35,6 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio
|
||||
const maxLength = Math.max(...composableLengths)
|
||||
const KEYED_FUNCTIONS_RE = new RegExp(`\\b(${[...keyedFunctions].map(f => escapeRE(f)).join('|')})\\b`)
|
||||
|
||||
const stringTypes: Array<string | undefined> = ['Literal', 'TemplateLiteral']
|
||||
const NUXT_LIB_RE = /node_modules\/(?:nuxt|nuxt3|nuxt-nightly)\//
|
||||
const SUPPORTED_EXT_RE = /\.(?:m?[jt]sx?|vue)/
|
||||
const SCRIPT_RE = /(?<=<script[^>]*>)[\s\S]*?(?=<\/script>)/i
|
||||
return {
|
||||
name: 'nuxt:composable-keys',
|
||||
enforce: 'post',
|
||||
|
@ -7,6 +7,11 @@ import { dirname, relative } from 'pathe'
|
||||
import MagicString from 'magic-string'
|
||||
import { isCSSRequest } from 'vite'
|
||||
|
||||
const PREFIX = 'virtual:public?'
|
||||
const CSS_URL_RE = /url\((\/[^)]+)\)/g
|
||||
const CSS_URL_SINGLE_RE = /url\(\/[^)]+\)/
|
||||
const RENDER_CHUNK_RE = /(?<= = )['"`]/
|
||||
|
||||
interface VitePublicDirsPluginOptions {
|
||||
dev?: boolean
|
||||
sourcemap?: boolean
|
||||
@ -16,11 +21,6 @@ interface VitePublicDirsPluginOptions {
|
||||
export const VitePublicDirsPlugin = createUnplugin((options: VitePublicDirsPluginOptions) => {
|
||||
const { resolveFromPublicAssets } = useResolveFromPublicAssets()
|
||||
|
||||
const PREFIX = 'virtual:public?'
|
||||
const CSS_URL_RE = /url\((\/[^)]+)\)/g
|
||||
const CSS_URL_SINGLE_RE = /url\(\/[^)]+\)/
|
||||
const RENDER_CHUNK_RE = /(?<= = )['"`]/
|
||||
|
||||
const devTransformPlugin: UnpluginOptions = {
|
||||
name: 'nuxt:vite-public-dir-resolution-dev',
|
||||
vite: {
|
||||
|
@ -1,3 +0,0 @@
|
||||
<template>
|
||||
<div>C</div>
|
||||
</template>
|
@ -1,5 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
D
|
||||
</div>
|
||||
</template>
|
@ -1,5 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
E
|
||||
</div>
|
||||
</template>
|
@ -1,7 +0,0 @@
|
||||
<template>
|
||||
<div><button @click="reloadNuxtApp()">EEE</button><C /> <NestedD /> <SuperNestedE /><div style="height: 3000px"/> <NuxtLink to="/second">EEEE</NuxtLink><NuxtLink to="/third">BBBB</NuxtLink></div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
definePageMeta({
|
||||
layout: false
|
||||
})</script>
|
@ -1,3 +0,0 @@
|
||||
<template>
|
||||
<div>Second</div>
|
||||
</template>
|
@ -1 +0,0 @@
|
||||
<template><div>EEEE</div></template>
|
Loading…
Reference in New Issue
Block a user