mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(vite): expand fs.allow
dirs to include app files (#20755)
This commit is contained in:
parent
cbcd254cd4
commit
8cca5cc9d8
@ -1,5 +1,6 @@
|
||||
import { existsSync } from 'node:fs'
|
||||
import * as vite from 'vite'
|
||||
import { join, resolve } from 'pathe'
|
||||
import { dirname, join, resolve } from 'pathe'
|
||||
import type { Nuxt, ViteConfig } from '@nuxt/schema'
|
||||
import { addVitePlugin, isIgnored, logger, resolvePath } from '@nuxt/kit'
|
||||
import replace from '@rollup/plugin-replace'
|
||||
@ -27,6 +28,25 @@ export async function bundle (nuxt: Nuxt) {
|
||||
const useAsyncEntry = nuxt.options.experimental.asyncEntry ||
|
||||
(nuxt.options.vite.devBundler === 'vite-node' && nuxt.options.dev)
|
||||
const entry = await resolvePath(resolve(nuxt.options.appDir, useAsyncEntry ? 'entry.async' : 'entry'))
|
||||
|
||||
let allowDirs = [
|
||||
nuxt.options.appDir,
|
||||
nuxt.options.workspaceDir,
|
||||
...nuxt.options._layers.map(l => l.config.rootDir),
|
||||
...Object.values(nuxt.apps).flatMap(app => [
|
||||
...app.components.map(c => dirname(c.filePath)),
|
||||
...app.plugins.map(p => dirname(p.src)),
|
||||
...app.middleware.map(m => dirname(m.path)),
|
||||
...Object.values(app.layouts || {}).map(l => dirname(l.file)),
|
||||
dirname(nuxt.apps.default.rootComponent!),
|
||||
dirname(nuxt.apps.default.errorComponent!)
|
||||
])
|
||||
].filter(d => d && existsSync(d))
|
||||
|
||||
for (const dir of allowDirs) {
|
||||
allowDirs = allowDirs.filter(d => !d.startsWith(dir) || d === dir)
|
||||
}
|
||||
|
||||
const ctx: ViteBuildContext = {
|
||||
nuxt,
|
||||
entry,
|
||||
@ -88,10 +108,7 @@ export async function bundle (nuxt: Nuxt) {
|
||||
server: {
|
||||
watch: { ignored: isIgnored },
|
||||
fs: {
|
||||
allow: [
|
||||
nuxt.options.appDir,
|
||||
...nuxt.options._layers.map(l => l.config.rootDir)
|
||||
]
|
||||
allow: [...new Set(allowDirs)]
|
||||
}
|
||||
}
|
||||
} satisfies ViteConfig,
|
||||
|
Loading…
Reference in New Issue
Block a user