Skip to content

Commit

Permalink
fix: handle theme files creation and deletion with Vite (#14260)
Browse files Browse the repository at this point in the history
Vite 'handleHotUpdate' hook is invoked only for file changes, not for creation nor deletion.
This change adds a watcher as well for those events and triggers theme regeneration
when theme file are added or deleted

Fixes #12154
  • Loading branch information
mcollovati committed Aug 3, 2022
1 parent ff3784c commit 227740a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions flow-server/src/main/resources/vite.generated.ts
Expand Up @@ -331,6 +331,17 @@ function themePlugin(opts): PluginOption {
config() {
processThemeResources(fullThemeOptions, console);
},
configureServer(server) {
function handleThemeFileCreateDelete(themeFile, stats) {
if (themeFile.startsWith(themeFolder)) {
const changed = path.relative(themeFolder, themeFile)
console.debug('Theme file ' + (!!stats ? 'created' : 'deleted'), changed);
processThemeResources(fullThemeOptions, console);
}
}
server.watcher.on('add', handleThemeFileCreateDelete);
server.watcher.on('unlink', handleThemeFileCreateDelete);
},
handleHotUpdate(context) {
const contextPath = path.resolve(context.file);
const themePath = path.resolve(themeFolder);
Expand Down

0 comments on commit 227740a

Please sign in to comment.