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"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -1027,11 +1028,20 @@ func (s *Site) processPartial(config *BuildCfg, init func(config *BuildCfg) erro
|
||||||
logger = helpers.NewDistinctFeedbackLogger()
|
logger = helpers.NewDistinctFeedbackLogger()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var isCSSConfigRe = regexp.MustCompile(`(postcss|tailwind)\.config\.js`)
|
||||||
|
var isCSSFileRe = regexp.MustCompile(`\.(css|scss|sass)`)
|
||||||
|
|
||||||
var cachePartitions []string
|
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 {
|
for _, ev := range events {
|
||||||
if assetsFilename := s.BaseFs.Assets.MakePathRelative(ev.Name); assetsFilename != "" {
|
if assetsFilename := s.BaseFs.Assets.MakePathRelative(ev.Name); assetsFilename != "" {
|
||||||
cachePartitions = append(cachePartitions, resources.ResourceKeyPartitions(assetsFilename)...)
|
cachePartitions = append(cachePartitions, resources.ResourceKeyPartitions(assetsFilename)...)
|
||||||
|
if !isCSSChange {
|
||||||
|
isCSSChange = isCSSFileRe.MatchString(assetsFilename) || isCSSConfigRe.MatchString(assetsFilename)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
id, found := s.eventToIdentity(ev)
|
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.
|
// These in memory resource caches will be rebuilt on demand.
|
||||||
for _, s := range s.h.Sites {
|
for _, s := range s.h.Sites {
|
||||||
s.ResourceSpec.ResourceCache.DeletePartitions(cachePartitions...)
|
s.ResourceSpec.ResourceCache.DeletePartitions(cachePartitions...)
|
||||||
|
if isCSSChange {
|
||||||
|
s.ResourceSpec.ResourceCache.DeleteContains("css", "scss", "sass")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tmplChanged || i18nChanged {
|
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