Skip to content

feat: support running the puma plugin in a bare puma process #459

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

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## next / unreleased

## v3.3.0 / unreleased

* Add support for running the puma plugin outside of `rails server`. (#458) @flavorjones


## v3.2.0 / 2025-01-10

* Improve the scaffold views by making positions, padding, and sizes more consistent, add titles to all pages, add hover states and semantic colors to buttons and links, and change border and focus colors on fields with errors. (#452) @patriciomacadden
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ This gem ships with a Puma plugin. To use it, add this line to your `puma.rb` co
plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development"
```

and then running `rails server` will run the Tailwind watch process in the background
and then running `rails server` (or just `puma`) will run the Tailwind watch process in the background.


#### Run `rails tailwindcss:watch`
Expand Down
8 changes: 6 additions & 2 deletions lib/puma/plugin/tailwindcss.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "puma/plugin"
require "tailwindcss/commands"

Puma::Plugin.create do
attr_reader :puma_pid, :tailwind_pid, :log_writer
Expand All @@ -11,8 +12,11 @@ def start(launcher)
# Using IO.popen(command, 'r+') will avoid watch_command read from $stdin.
# If we use system(*command) instead, IRB and Debug can't read from $stdin
# correctly bacause some keystrokes will be taken by watch_command.
IO.popen(Tailwindcss::Commands.watch_command, 'r+') do |io|
IO.copy_stream(io, $stdout)
begin
IO.popen(Tailwindcss::Commands.watch_command, 'r+') do |io|
IO.copy_stream(io, $stdout)
end
rescue Interrupt
end
end

Expand Down
10 changes: 6 additions & 4 deletions lib/tailwindcss/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ module Tailwindcss
module Commands
class << self
def compile_command(debug: false, **kwargs)
rails_root = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd)

command = [
Tailwindcss::Ruby.executable(**kwargs),
"-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
"-o", Rails.root.join("app/assets/builds/tailwind.css").to_s,
"-c", Rails.root.join("config/tailwind.config.js").to_s,
"-i", rails_root.join("app/assets/stylesheets/application.tailwind.css").to_s,
"-o", rails_root.join("app/assets/builds/tailwind.css").to_s,
"-c", rails_root.join("config/tailwind.config.js").to_s,
]

command << "--minify" unless (debug || rails_css_compressor?)

postcss_path = Rails.root.join("config/postcss.config.js")
postcss_path = rails_root.join("config/postcss.config.js")
command += ["--postcss", postcss_path.to_s] if File.exist?(postcss_path)

command
Expand Down
Loading