Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work in progress: Make Hugo work with tailwindcss-jit #8345

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/hugo/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func GetExecEnviron(workDir string, cfg config.Provider, fs afero.Fs) []string {
if np := os.Getenv("NODE_PATH"); np != "" {
nodepath = workDir + string(os.PathListSeparator) + np
}

// For tailwindcss-jit -- we must make sure that we don't start their watcher
// as that currently will not work.
// See https://github.com/tailwindlabs/tailwindcss-jit#getting-started
config.SetEnvVars(&env, "TAILWIND_MODE", "build")

config.SetEnvVars(&env, "NODE_PATH", nodepath)
config.SetEnvVars(&env, "PWD", workDir)
config.SetEnvVars(&env, "HUGO_ENVIRONMENT", cfg.GetString("environment"))
Expand Down
5 changes: 5 additions & 0 deletions common/loggers/loggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,8 @@ func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle
errors: errorBuff,
}
}

func TimeTrack(start time.Time, name string) {
elapsed := time.Since(start)
fmt.Printf("%s took %s\n", name, elapsed)
}
2 changes: 1 addition & 1 deletion resources/resource_transformers/babel/babel.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
// Create compile into a real temp file:
// 1. separate stdout/stderr messages from babel (https://github.com/gohugoio/hugo/issues/8136)
// 2. allow generation and retrieval of external source map.
compileOutput, err := ioutil.TempFile("", "compileOut-*.js")
compileOutput, err := ioutil.TempFile("", "babel-out-*.js")
if err != nil {
return err
}
Expand Down
26 changes: 15 additions & 11 deletions resources/resource_transformers/postcss/postcss.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import (
"encoding/hex"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"

"github.com/cli/safeexec"

Expand Down Expand Up @@ -141,6 +143,7 @@ func (t *postcssTransformation) Key() internal.ResourceTransformationKey {
// npm install -g postcss-cli
// npm install -g autoprefixer
func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationCtx) error {
defer loggers.TimeTrack(time.Now(), "PostCSS")
const localPostCSSPath = "node_modules/.bin/"
const binaryName = "postcss"

Expand Down Expand Up @@ -178,11 +181,18 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
}
}

var cmdArgs []string
// tailwindcss-jit currently does not support reading from stdin.
inFile, err := ioutil.TempFile("", "postcss-in-*.css")
if err != nil {
return err
}
defer os.Remove(inFile.Name())

cmdArgs := []string{inFile.Name()}

if configFile != "" {
logger.Infoln("postcss: use config file", configFile)
cmdArgs = []string{"--config", configFile}
cmdArgs = append(cmdArgs, "--config", configFile)
}

if optArgs := t.options.toArgs(); len(optArgs) > 0 {
Expand All @@ -202,11 +212,6 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC

cmd.Env = hugo.GetExecEnviron(t.rs.WorkingDir, t.rs.Cfg, t.rs.BaseFs.Assets.Fs)

stdin, err := cmd.StdinPipe()
if err != nil {
return err
}

src := ctx.From

imp := newImportResolver(
Expand All @@ -223,10 +228,9 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
}
}

go func() {
defer stdin.Close()
io.Copy(stdin, src)
}()
if _, err := io.Copy(inFile, src); err != nil {
return err
}

err = cmd.Run()
if err != nil {
Expand Down