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 bf09205
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,8 @@
## Unreleased

* Correctly handle paths with embedded spaces. [#184](https://github.com/rails/tailwindcss-rails/issues/184) by [@flavorjones](https://github.com/flavorjones)
* Rake tasks accept a `debug` argument to generate unminified assets, e.g. `tailwindcss:build[debug]`. [#198](https://github.com/rails/tailwindcss-rails/pull/198) by [@flavorjones](https://github.com/flavorjones)
* The `build` and `watch` tasks accept a `debug` argument to generate unminified assets: `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`. [#198](https://github.com/rails/tailwindcss-rails/pull/198) by [@flavorjones](https://github.com/flavorjones)
* The `watch` task accepts a `poll` argument to use polling instead of file system events: `rails tailwindcss:watch[poll]`. [#199](https://github.com/rails/tailwindcss-rails/pull/199) by [@flavorjones](https://github.com/flavorjones)


## v2.0.12 / 2022-08-10
Expand Down
5 changes: 5 additions & 0 deletions README.md
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
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
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
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 bf09205

Please sign in to comment.