Make sure CSS is rebuilt when postcss.config.js or tailwind.config.js changes

Fixes #7715
This commit is contained in:
Bjørn Erik Pedersen 2020-09-20 13:34:45 +02:00
parent 473b6610d5
commit 3acde9ae04
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
2 changed files with 32 additions and 0 deletions

View file

@ -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 {

View file

@ -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)
}
}
}