From 56202521d37c23e99c9911d776f9339a7057956d Mon Sep 17 00:00:00 2001 From: Matt Dudek Date: Wed, 14 Apr 2021 21:26:12 -0400 Subject: [PATCH] modified js.Build to always create a temporary output dir and to check if any of the files are of type css to allow css imports in js files --- resources/resource_transformers/js/build.go | 29 ++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/resources/resource_transformers/js/build.go b/resources/resource_transformers/js/build.go index bd74c98edbb..bb9f87b6a44 100644 --- a/resources/resource_transformers/js/build.go +++ b/resources/resource_transformers/js/build.go @@ -96,13 +96,11 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx return err } - if buildOptions.Sourcemap == api.SourceMapExternal && buildOptions.Outdir == "" { - buildOptions.Outdir, err = ioutil.TempDir(os.TempDir(), "compileOutput") - if err != nil { - return err - } - defer os.Remove(buildOptions.Outdir) + buildOptions.Outdir, err = ioutil.TempDir(os.TempDir(), "compileOutput") + if err != nil { + return err } + defer os.Remove(buildOptions.Outdir) if opts.Inject != nil { // Resolve the absolute filenames. @@ -182,6 +180,25 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx return errors[0] } + for _, outputFile := range result.OutputFiles { + if strings.HasSuffix(outputFile.Path, ".css") { + ctx.OutMediaType = media.CSSType + // below is the code from ctx.PublishSourceMap with .css instead of .map + target := ctx.OutPath + ".css" + f, err := ctx.OpenResourcePublisher(target) + if err != nil { + return err + } + defer f.Close() + _, err = f.Write([]byte(outputFile.Contents)) + if err != nil { + return err + } + } + } + + ctx.OutMediaType = media.JavascriptType + if buildOptions.Sourcemap == api.SourceMapExternal { content := string(result.OutputFiles[1].Contents) symPath := path.Base(ctx.OutPath) + ".map"