add bundler stuff

This commit is contained in:
2026-07-08 16:59:00 -04:00
parent 2a5fbffaa2
commit ba3d87c27f
12 changed files with 425 additions and 70 deletions

View File

@@ -69,9 +69,24 @@ func compileCSSBundle(label string, twSources []string, outName string) (bundleS
}
cssDir := filepath.Dir(entryPath)
// Candidate classes come from the app sources (patterns relative to the css
// dir) plus the shared kit tree scanned directly, so kit component classes are
// present even though the kit lives outside the app frontend.
candidates := scanSources(cssDir, twSources)
kitCands := scanSources(kitSrcDir(), []string{"**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"})
candidates = dedupStrings(append(candidates, kitCands...))
compiled, count, err := twCompile(string(src), cssDir, candidates)
// Prepend the shared @theme scaffold (kjol web/styles/theme.css) ahead of the
// app's brand style.css so its tokens/vars are in scope. Absent in single-tree
// mode (the app's style.css is already complete).
input := string(src)
if tp := themeCSSPath(); tp != "" {
if theme, e := os.ReadFile(tp); e == nil {
input = string(theme) + "\n" + input
}
}
compiled, count, err := twCompile(input, cssDir, candidates)
if err != nil {
return bundleStats{}, fmt.Errorf("tailwind compile (%s): %w", label, err)
}
@@ -89,3 +104,16 @@ func compileCSSBundle(label string, twSources []string, outName string) (bundleS
}
return bundleStats{files: len(candidates), bytes: len(minified)}, nil
}
// dedupStrings returns in with duplicates removed, preserving first-seen order.
func dedupStrings(in []string) []string {
seen := make(map[string]bool, len(in))
out := make([]string, 0, len(in))
for _, s := range in {
if !seen[s] {
seen[s] = true
out = append(out, s)
}
}
return out
}