Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: support polling instead of fs events when watching
Polling was added upstream in 3.1.0.

Suggested by #168
  • Loading branch information
flavorjones committed Sep 3, 2022
commit bf09205b0b78c9c0498536a660dbb1d78d6745b7
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
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
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