mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
perf(nuxt): avoid duplicate iterations over layers (#24730)
This commit is contained in:
parent
86a7f37479
commit
eff684326b
@ -107,8 +107,10 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Resolve layouts/ from all config layers
|
// Resolve layouts/ from all config layers
|
||||||
|
const layerConfigs = nuxt.options._layers.map(layer => layer.config)
|
||||||
|
const reversedConfigs = layerConfigs.slice().reverse()
|
||||||
app.layouts = {}
|
app.layouts = {}
|
||||||
for (const config of nuxt.options._layers.map(layer => layer.config)) {
|
for (const config of layerConfigs) {
|
||||||
const layoutDir = (config.rootDir === nuxt.options.rootDir ? nuxt.options : config).dir?.layouts || 'layouts'
|
const layoutDir = (config.rootDir === nuxt.options.rootDir ? nuxt.options : config).dir?.layouts || 'layouts'
|
||||||
const layoutFiles = await resolveFiles(config.srcDir, `${layoutDir}/**/*{${nuxt.options.extensions.join(',')}}`)
|
const layoutFiles = await resolveFiles(config.srcDir, `${layoutDir}/**/*{${nuxt.options.extensions.join(',')}}`)
|
||||||
for (const file of layoutFiles) {
|
for (const file of layoutFiles) {
|
||||||
@ -119,7 +121,7 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
|
|||||||
|
|
||||||
// Resolve middleware/ from all config layers, layers first
|
// Resolve middleware/ from all config layers, layers first
|
||||||
app.middleware = []
|
app.middleware = []
|
||||||
for (const config of nuxt.options._layers.map(layer => layer.config).reverse()) {
|
for (const config of reversedConfigs) {
|
||||||
const middlewareDir = (config.rootDir === nuxt.options.rootDir ? nuxt.options : config).dir?.middleware || 'middleware'
|
const middlewareDir = (config.rootDir === nuxt.options.rootDir ? nuxt.options : config).dir?.middleware || 'middleware'
|
||||||
const middlewareFiles = await resolveFiles(config.srcDir, `${middlewareDir}/*{${nuxt.options.extensions.join(',')}}`)
|
const middlewareFiles = await resolveFiles(config.srcDir, `${middlewareDir}/*{${nuxt.options.extensions.join(',')}}`)
|
||||||
app.middleware.push(...middlewareFiles.map((file) => {
|
app.middleware.push(...middlewareFiles.map((file) => {
|
||||||
@ -130,7 +132,7 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
|
|||||||
|
|
||||||
// Resolve plugins, first extended layers and then base
|
// Resolve plugins, first extended layers and then base
|
||||||
app.plugins = []
|
app.plugins = []
|
||||||
for (const config of nuxt.options._layers.map(layer => layer.config).reverse()) {
|
for (const config of reversedConfigs) {
|
||||||
const pluginDir = (config.rootDir === nuxt.options.rootDir ? nuxt.options : config).dir?.plugins || 'plugins'
|
const pluginDir = (config.rootDir === nuxt.options.rootDir ? nuxt.options : config).dir?.plugins || 'plugins'
|
||||||
app.plugins.push(...[
|
app.plugins.push(...[
|
||||||
...(config.plugins || []),
|
...(config.plugins || []),
|
||||||
@ -157,7 +159,7 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
|
|||||||
|
|
||||||
// Resolve app.config
|
// Resolve app.config
|
||||||
app.configs = []
|
app.configs = []
|
||||||
for (const config of nuxt.options._layers.map(layer => layer.config)) {
|
for (const config of layerConfigs) {
|
||||||
const appConfigPath = await findPath(resolve(config.srcDir, 'app.config'))
|
const appConfigPath = await findPath(resolve(config.srcDir, 'app.config'))
|
||||||
if (appConfigPath) {
|
if (appConfigPath) {
|
||||||
app.configs.push(appConfigPath)
|
app.configs.push(appConfigPath)
|
||||||
|
Loading…
Reference in New Issue
Block a user