()
| 238 | } |
| 239 | |
| 240 | const registerHooks = () => { |
| 241 | if (twCtx.use().meta?.disableHMR) return |
| 242 | |
| 243 | const reloadConfigTemplate = async () => { |
| 244 | const { dst } = twCtx.use() |
| 245 | await loadConfigs() |
| 246 | |
| 247 | setTimeout(async () => { |
| 248 | await updateTemplates({ filter: t => t.dst === dst || dst?.endsWith(t.filename) || false }) |
| 249 | await nuxt.callHook('tailwindcss:internal:regenerateTemplates', { configTemplateUpdated: true }) |
| 250 | }, 100) |
| 251 | } |
| 252 | |
| 253 | nuxt.hook('app:templatesGenerated', async (_app, templates) => { |
| 254 | if (Array.isArray(templates) && templates?.some(t => Object.keys(configUpdatedHook).includes(t.dst))) { |
| 255 | await reloadConfigTemplate() |
| 256 | } |
| 257 | }) |
| 258 | |
| 259 | if (moduleOptions.experimental?.strictScanContentPaths) { |
| 260 | nuxt.hook('pages:extend', async (pages) => { |
| 261 | const newPageFiles = resolvePageFiles(pages) |
| 262 | |
| 263 | if (newPageFiles.length !== pagesContentPath.tryUse()?.length) { |
| 264 | pagesContentPath.set(newPageFiles, true) |
| 265 | await reloadConfigTemplate() |
| 266 | } |
| 267 | }) |
| 268 | |
| 269 | nuxt.hook('components:extend', async (components) => { |
| 270 | const newComponentFiles = components.map(c => c.filePath) |
| 271 | |
| 272 | if (newComponentFiles.length !== componentsContentPath.tryUse()?.length) { |
| 273 | componentsContentPath.set(newComponentFiles, true) |
| 274 | await reloadConfigTemplate() |
| 275 | } |
| 276 | }) |
| 277 | } |
| 278 | else { |
| 279 | nuxt.hook('pages:extend', () => reloadConfigTemplate()) |
| 280 | } |
| 281 | |
| 282 | nuxt.hook('vite:serverCreated', (server) => { |
| 283 | nuxt.hook('tailwindcss:internal:regenerateTemplates', (data) => { |
| 284 | if (!data || !data.configTemplateUpdated) return |
| 285 | const ctx = twCtx.use() |
| 286 | const configFile = ctx.dst && server.moduleGraph.getModuleById(ctx.dst) |
| 287 | // eslint-disable-next-line @typescript-eslint/no-unused-expressions |
| 288 | configFile && server.moduleGraph.invalidateModule(configFile) |
| 289 | }) |
| 290 | }) |
| 291 | |
| 292 | // eslint-disable-next-line @typescript-eslint/no-unused-expressions |
| 293 | moduleOptions.exposeConfig && nuxt.hook('builder:watch', async (_, path) => { |
| 294 | if (Object.keys(configUpdatedHook).includes(join(nuxt.options.rootDir, path))) { |
| 295 | const ctx = twCtx.use() |
| 296 | setTimeout(async () => { |
| 297 | await import(ctx.dst!).then(async (_config) => { |
nothing calls this directly
no test coverage detected