@@ -15,6 +15,7 @@ import (
1515 "github.com/gohugoio/hugo/resources/resource"
1616 "github.com/gohugoio/hugo/resources/resource_transformers/babel"
1717 "github.com/gohugoio/hugo/resources/resource_transformers/cssjs"
18+ jstransform "github.com/gohugoio/hugo/resources/resource_transformers/js"
1819 "github.com/gohugoio/hugo/resources/resource_transformers/tocss/dartsass"
1920 "github.com/gohugoio/hugo/resources/resource_transformers/tocss/sass"
2021 "github.com/gohugoio/hugo/resources/resource_transformers/tocss/scss"
@@ -32,6 +33,7 @@ type Namespace struct {
3233 postcssClient * cssjs.PostCSSClient
3334 tailwindcssClient * cssjs.TailwindCSSClient
3435 babelClient * babel.Client
36+ jsTransformClient * jstransform.Client
3537
3638 // The Dart Client requires a os/exec process, so only
3739 // create it if we really need it.
@@ -147,6 +149,33 @@ func (ns *Namespace) Sass(args ...any) (resource.Resource, error) {
147149 return client .ToCSS (r , m )
148150}
149151
152+ // Build processes the given CSS Resource with ESBuild.
153+ // Note that this method is identical to the one in the js Namespace.
154+ func (ns * Namespace ) Build (args ... any ) (resource.Resource , error ) {
155+ var (
156+ r resources.ResourceTransformer
157+ m map [string ]any
158+ targetPath string
159+ err error
160+ ok bool
161+ )
162+
163+ r , targetPath , ok = resourcehelpers .ResolveIfFirstArgIsString (args )
164+
165+ if ! ok {
166+ r , m , err = resourcehelpers .ResolveArgs (args )
167+ if err != nil {
168+ return nil , err
169+ }
170+ }
171+
172+ if targetPath != "" {
173+ m = map [string ]any {"targetPath" : targetPath }
174+ }
175+
176+ return ns .jsTransformClient .Process (r , m )
177+ }
178+
150179func init () {
151180 f := func (d * deps.Deps ) * internal.TemplateFuncsNamespace {
152181 scssClient , err := scss .New (d .BaseFs .Assets , d .ResourceSpec )
@@ -159,6 +188,7 @@ func init() {
159188 postcssClient : cssjs .NewPostCSSClient (d .ResourceSpec ),
160189 tailwindcssClient : cssjs .NewTailwindCSSClient (d .ResourceSpec ),
161190 babelClient : babel .New (d .ResourceSpec ),
191+ jsTransformClient : jstransform .New (d .BaseFs .Assets , d .ResourceSpec , true ),
162192 }
163193
164194 ns := & internal.TemplateFuncsNamespace {
0 commit comments