mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): recompile templates on change
events (#29954)
This commit is contained in:
parent
e9f7cb7f89
commit
4924e26329
@ -10,7 +10,6 @@ import { generateApp as _generateApp, createApp } from './app'
|
|||||||
import { checkForExternalConfigurationFiles } from './external-config-files'
|
import { checkForExternalConfigurationFiles } from './external-config-files'
|
||||||
import { cleanupCaches, getVueHash } from './cache'
|
import { cleanupCaches, getVueHash } from './cache'
|
||||||
|
|
||||||
const IS_RESTART_PATH_RE = /^(?:app\.|error\.|plugins\/|middleware\/|layouts\/)/i
|
|
||||||
export async function build (nuxt: Nuxt) {
|
export async function build (nuxt: Nuxt) {
|
||||||
const app = createApp(nuxt)
|
const app = createApp(nuxt)
|
||||||
nuxt.apps.default = app
|
nuxt.apps.default = app
|
||||||
@ -21,19 +20,24 @@ export async function build (nuxt: Nuxt) {
|
|||||||
if (nuxt.options.dev) {
|
if (nuxt.options.dev) {
|
||||||
watch(nuxt)
|
watch(nuxt)
|
||||||
nuxt.hook('builder:watch', async (event, relativePath) => {
|
nuxt.hook('builder:watch', async (event, relativePath) => {
|
||||||
if (event === 'change') { return }
|
// Unset mainComponent and errorComponent if app or error component is changed
|
||||||
|
if (event === 'add' || event === 'unlink') {
|
||||||
const path = resolve(nuxt.options.srcDir, relativePath)
|
const path = resolve(nuxt.options.srcDir, relativePath)
|
||||||
const relativePaths = nuxt.options._layers.map(l => relative(l.config.srcDir || l.cwd, path))
|
for (const layer of nuxt.options._layers) {
|
||||||
const restartPath = relativePaths.find(relativePath => IS_RESTART_PATH_RE.test(relativePath))
|
const relativePath = relative(layer.config.srcDir || layer.cwd, path)
|
||||||
if (restartPath) {
|
if (relativePath.match(/^app\./i)) {
|
||||||
if (restartPath.startsWith('app')) {
|
|
||||||
app.mainComponent = undefined
|
app.mainComponent = undefined
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if (restartPath.startsWith('error')) {
|
if (relativePath.match(/^error\./i)) {
|
||||||
app.errorComponent = undefined
|
app.errorComponent = undefined
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recompile app templates
|
||||||
await generateApp()
|
await generateApp()
|
||||||
}
|
|
||||||
})
|
})
|
||||||
nuxt.hook('builder:generateApp', (options) => {
|
nuxt.hook('builder:generateApp', (options) => {
|
||||||
// Bypass debounce if we are selectively invalidating templates
|
// Bypass debounce if we are selectively invalidating templates
|
||||||
|
@ -107,12 +107,9 @@ export default defineNuxtModule<Partial<ImportsOptions>>({
|
|||||||
|
|
||||||
const priorities = nuxt.options._layers.map((layer, i) => [layer.config.srcDir, -i] as const).sort(([a], [b]) => b.length - a.length)
|
const priorities = nuxt.options._layers.map((layer, i) => [layer.config.srcDir, -i] as const).sort(([a], [b]) => b.length - a.length)
|
||||||
|
|
||||||
|
const IMPORTS_TEMPLATE_RE = /\/imports\.(?:d\.ts|mjs)$/
|
||||||
function isImportsTemplate (template: ResolvedNuxtTemplate) {
|
function isImportsTemplate (template: ResolvedNuxtTemplate) {
|
||||||
return [
|
return IMPORTS_TEMPLATE_RE.test(template.filename)
|
||||||
'/types/imports.d.ts',
|
|
||||||
'/imports.d.ts',
|
|
||||||
'/imports.mjs',
|
|
||||||
].some(i => template.filename.endsWith(i))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const regenerateImports = async () => {
|
const regenerateImports = async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user