Skip to content

Commit

Permalink
feat: support polling instead of fs events when watching
Browse files Browse the repository at this point in the history
Polling was added upstream in 3.1.0.

Suggested by #168
  • Loading branch information
flavorjones committed Sep 3, 2022
1 parent 4da93dd commit 17ebb1c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ While you're developing your application, you want to run Tailwind in "watch" mo

If you are running `rails tailwindcss:watch` as a process in a Docker container, set `tty: true` in `docker-compose.yml` for the appropriate container to keep the watch process running.

If you are running `rails tailwindcss:watch` on a system that doesn't fully support file system events, pass a `poll` argument to the task to instruct tailwindcss to instead use polling: `rails tailwindcss:watch[poll]`. If you use `bin/dev` then you should modify your `Procfile.dev`.


### Debugging with unminified assets

If you want unminified assets, you can pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`.

Note that you can combine task options, e.g. `rails tailwindcss:watch[debug,poll]`.


### Custom inputs or outputs

Expand Down
7 changes: 5 additions & 2 deletions lib/tailwindcss/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ def compile_command(debug: false, **kwargs)
end
end

def watch_command(**kwargs)
compile_command(**kwargs) << "-w"
def watch_command(poll: false, **kwargs)
compile_command(**kwargs).tap do |command|
command << "-w"
command << "-p" if poll
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/build.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace :tailwindcss do
desc "Watch and build your Tailwind CSS on file changes"
task :watch do |_, args|
debug = args.extras.include?("debug")
command = Tailwindcss::Commands.watch_command(debug: debug)
poll = args.extras.include?("poll")
command = Tailwindcss::Commands.watch_command(debug: debug, poll: poll)
puts command.inspect
system(*command)
end
Expand Down
9 changes: 9 additions & 0 deletions test/lib/tailwindcss/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,22 @@ def mock_exe_directory(platform)
assert_kind_of(Array, actual)
assert_equal(executable, actual.first)
assert_includes(actual, "-w")
refute_includes(actual, "-p")
assert_includes(actual, "--minify")

actual = Tailwindcss::Commands.watch_command(exe_path: dir, debug: true)
assert_kind_of(Array, actual)
assert_equal(executable, actual.first)
assert_includes(actual, "-w")
refute_includes(actual, "-p")
refute_includes(actual, "--minify")

actual = Tailwindcss::Commands.watch_command(exe_path: dir, poll: true)
assert_kind_of(Array, actual)
assert_equal(executable, actual.first)
assert_includes(actual, "-w")
assert_includes(actual, "-p")
assert_includes(actual, "--minify")
end
end
end
Expand Down

0 comments on commit 17ebb1c

Please sign in to comment.