mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Make sure CSS is rebuilt when postcss.config.js or tailwind.config.js changes
Fixes #7715
This commit is contained in:
parent
473b6610d5
commit
3acde9ae04
2 changed files with 32 additions and 0 deletions
|
@ -23,6 +23,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -1027,11 +1028,20 @@ func (s *Site) processPartial(config *BuildCfg, init func(config *BuildCfg) erro
|
|||
logger = helpers.NewDistinctFeedbackLogger()
|
||||
)
|
||||
|
||||
var isCSSConfigRe = regexp.MustCompile(`(postcss|tailwind)\.config\.js`)
|
||||
var isCSSFileRe = regexp.MustCompile(`\.(css|scss|sass)`)
|
||||
|
||||
var cachePartitions []string
|
||||
// Special case
|
||||
// TODO(bep) I have a ongoing branch where I have redone the cache. Consider this there.
|
||||
var isCSSChange bool
|
||||
|
||||
for _, ev := range events {
|
||||
if assetsFilename := s.BaseFs.Assets.MakePathRelative(ev.Name); assetsFilename != "" {
|
||||
cachePartitions = append(cachePartitions, resources.ResourceKeyPartitions(assetsFilename)...)
|
||||
if !isCSSChange {
|
||||
isCSSChange = isCSSFileRe.MatchString(assetsFilename) || isCSSConfigRe.MatchString(assetsFilename)
|
||||
}
|
||||
}
|
||||
|
||||
id, found := s.eventToIdentity(ev)
|
||||
|
@ -1078,6 +1088,9 @@ func (s *Site) processPartial(config *BuildCfg, init func(config *BuildCfg) erro
|
|||
// These in memory resource caches will be rebuilt on demand.
|
||||
for _, s := range s.h.Sites {
|
||||
s.ResourceSpec.ResourceCache.DeletePartitions(cachePartitions...)
|
||||
if isCSSChange {
|
||||
s.ResourceSpec.ResourceCache.DeleteContains("css", "scss", "sass")
|
||||
}
|
||||
}
|
||||
|
||||
if tmplChanged || i18nChanged {
|
||||
|
|
|
@ -295,3 +295,22 @@ func (c *ResourceCache) DeletePartitions(partitions ...string) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func (c *ResourceCache) DeleteContains(parts ...string) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
for k := range c.cache {
|
||||
clear := false
|
||||
for _, part := range parts {
|
||||
if strings.Contains(k, part) {
|
||||
clear = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if clear {
|
||||
delete(c.cache, k)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue