mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix: force rebuild on new files being added (#136)
This commit is contained in:
parent
85da52d390
commit
e1f409ea51
@ -79,16 +79,8 @@ async function _build (nitroContext: NitroContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _watch (nitroContext: NitroContext) {
|
function startRollupWatcher (nitroContext: NitroContext) {
|
||||||
const watcher = rollupWatch(nitroContext.rollupConfig)
|
const watcher = rollupWatch(nitroContext.rollupConfig)
|
||||||
|
|
||||||
nitroContext.scannedMiddleware = await scanMiddleware(nitroContext._nuxt.serverDir,
|
|
||||||
(middleware, event, file) => {
|
|
||||||
nitroContext.scannedMiddleware = middleware
|
|
||||||
watcher.emit(event, file)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
let start
|
let start
|
||||||
|
|
||||||
watcher.on('event', (event) => {
|
watcher.on('event', (event) => {
|
||||||
@ -114,4 +106,19 @@ async function _watch (nitroContext: NitroContext) {
|
|||||||
// consola.error(event.error)
|
// consola.error(event.error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
return watcher
|
||||||
|
}
|
||||||
|
|
||||||
|
async function _watch (nitroContext: NitroContext) {
|
||||||
|
let watcher = startRollupWatcher(nitroContext)
|
||||||
|
|
||||||
|
nitroContext.scannedMiddleware = await scanMiddleware(nitroContext._nuxt.serverDir,
|
||||||
|
(middleware, event) => {
|
||||||
|
nitroContext.scannedMiddleware = middleware
|
||||||
|
if (['add', 'addDir'].includes(event)) {
|
||||||
|
watcher.close()
|
||||||
|
watcher = startRollupWatcher(nitroContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ function filesToMiddleware (files: string[], baseDir: string, basePath: string,
|
|||||||
.map(m => ({ ...m, ...overrides }))
|
.map(m => ({ ...m, ...overrides }))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function scanMiddleware (serverDir: string, onChange?: Function): Promise<ServerMiddleware[]> {
|
export function scanMiddleware (serverDir: string, onChange?: (results: ServerMiddleware[], event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', file: string) => void): Promise<ServerMiddleware[]> {
|
||||||
const pattern = '**/*.{js,ts}'
|
const pattern = '**/*.{js,ts}'
|
||||||
const globalDir = resolve(serverDir, 'middleware')
|
const globalDir = resolve(serverDir, 'middleware')
|
||||||
const apiDir = resolve(serverDir, 'api')
|
const apiDir = resolve(serverDir, 'api')
|
||||||
|
Loading…
Reference in New Issue
Block a user