diff --git a/CHANGELOG.md b/CHANGELOG.md index f1f8928..099f7d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index c59da8a..acaa69a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index 0bc52d5..136b5ee 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -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 diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index da78465..258930e 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -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 diff --git a/test/lib/tailwindcss/commands_test.rb b/test/lib/tailwindcss/commands_test.rb index 8734665..7ff0c5c 100644 --- a/test/lib/tailwindcss/commands_test.rb +++ b/test/lib/tailwindcss/commands_test.rb @@ -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