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

--watch doesn't work in background #9870

Closed
stfnx opened this issue Nov 18, 2022 · 7 comments · Fixed by #9966
Closed

--watch doesn't work in background #9870

stfnx opened this issue Nov 18, 2022 · 7 comments · Fixed by #9966
Assignees

Comments

@stfnx
Copy link

stfnx commented Nov 18, 2022

What version of Tailwind CSS are you using?

v3.2.4

What build tool (or framework if it abstracts the build tool) are you using?

TailwindCSS standalone binary

What operating system are you using?

Happens on both Linux and Windows

Describe your issue

I have a shell script to start my development server:

#!/bin/env bash

# Get absolute path to project's root direcotry
PROJECT_ROOT=$(realpath "$0")
PROJECT_ROOT=$(dirname "$PROJECT_ROOT")

# Run tailwind watcher in background
${PROJECT_ROOT}/tailwind/tailwind_bin_v3.2.4 \
--watch \
--config ${PROJECT_ROOT}/tailwind/config.js \
--input ${PROJECT_ROOT}/tailwind/main.css \
--output ${PROJECT_ROOT}/app/static/css/tailwind.css &

# Run flask dev server in debug mode
flask --debug run

This worked perfectly fine with TailwindCSS v3.1.8 but now I upgraded to v3.2.4 and it doens't work anymore.

Downgrading to v3.1.8 makes it work again.

Expected behaviour

When running the script, the Tailwind watcher should run as a background process and I should see its output (Rebuilding...Done in 267ms) in stdout.

Actual behaviour

The Tailwind watcher doesn't run and I can't see any output in stdout.

Note

When running the command in foreground (without & at the end) it works as expected. So as a workaround I run flask in background and tailwind in foreground.

@thecrypticace
Copy link
Contributor

Hey, I've added a --watch=always option to the CLI to work around this behavior. It should be in our insiders build in a few minutes. Once it's published you can test it by using npm install tailwindcss@insiders.

I've verified this on my end that it seems to work. Please let me know if you encounter any more issues. Thanks! ✨

@stfnx
Copy link
Author

stfnx commented Dec 4, 2022

Are prebuilt standalone binaries distributed for the insider version? I'm not going to use npm.

@gypsydave5
Copy link

I was running the tailwindcss standalone cli binary on a watch from inside a Gradle task - the --watch=always trick worked like a charm. Just leaving this here to say thanks and as documentation

@hayesall
Copy link

This is inconsistent for me with zsh, but nohup seems to be an okay workaround:

nohup npx tailwindcss -i ./input.css -o ./output.css --watch=always </dev/null &

# Optional: capture an id and send the kill signal when finished
tid=$!
kill -9 $tid

@JamesHutchison
Copy link

JamesHutchison commented Jun 30, 2024

Can we make this the default behavior or error if it gets an immediate EOF or something? If it starts in a non-interactive shell, ending immediately can not be the desired behavior. This cost me several hours of debugging trying to figure out why it wasn't giving output, wasn't updating, wasn't erroring, but worked just fine when I ran it manually.

This isn't in the help output either.

Usage:
   tailwindcss [--input input.css] [--output output.css] [--watch] [options...]
   tailwindcss init [--full] [--postcss] [options...]

Commands:
   init [options]

Options:
   -i, --input              Input file
   -o, --output             Output file
   -w, --watch              Watch for changes and rebuild as needed
   -p, --poll               Use polling instead of filesystem events when watching
       --content            Content paths to use for removing unused classes
       --postcss            Load custom PostCSS configuration
   -m, --minify             Minify the output
   -c, --config             Path to a custom config file
       --no-autoprefixer    Disable autoprefixer
   -h, --help               Display usage information

@tamara-nexus
Copy link

tamara-nexus commented Jul 29, 2024

Hello,

This thread helped me. Can someone verify if this is the best way to have a bash script compile multiple separate files at once and watch for change?

My main issue was that:

npx tailwindcss -i "$input_file" -o "$output_file" --watch &
Did not generate any output files.

npx tailwindcss -i "$input_file" -o "$output_file"
This generated output but only once. No watch.

Based on this thread:
npx tailwindcss -i "$input_file" -o "$output_file" --watch=always &
This made my script work

Full bash script:

BASE_DIR="./src"

INPUT_FILES=($(find "$BASE_DIR" -type f -name '*-tw.css'))

process_file() {
  local input_file=$1
  local output_file="${input_file%-tw.css}.css"
  npx tailwindcss -i "$input_file" -o "$output_file" --watch=always &
}

export -f process_file

for file in "${INPUT_FILES[@]}"; do
  process_file "$file"
done

wait

@reorx
Copy link

reorx commented Oct 18, 2024

this drives me mad man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants