Skip to content

Allow postcss #222

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

Closed
wants to merge 8 commits into from
Closed
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ DEPENDENCIES
tailwindcss-rails!

BUNDLED WITH
2.3.14
2.3.25
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ If you are running `rails tailwindcss:watch` as a process in a Docker container,
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`.


### Using postcss

The tailwind cli supports passing a postcss.config.js file. This might be necessary if you want to use postcss plugins (e.g. postcss-css-variables). This gem checks if a postcss.config.js exists, in which case it is used for building tailwind assets.

### 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]`.
Expand Down Expand Up @@ -147,6 +151,14 @@ The inline version also works:
<section class="bg-[url('image.svg')]">Has the image as it's background</section>
```

### Contributing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a CONTRIBUTING.md file which I think covers this topic. If not, please make changes to that file and not the user-facing README.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added content addressing how to develop against this gem in e22c8ce


If you want to fork this repo and test this gem locally in your projects, you will need to run `rake package` (the process this gem uses to generate platform-related gem versions, e.g. x86_64-linux, x86_64-darwin, etc). You can now point the local version of the gem in your Gemfile:

```ruby
gem 'tailwindcss-rails', '2.0.18', path: '/path/to/your/local/gem'
```

## License

Tailwind for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
Expand Down
6 changes: 4 additions & 2 deletions lib/tailwindcss/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,23 @@ def executable(
exe_path
end

def compile_command(debug: false, **kwargs)
def compile_command(debug: false, postcss: false, **kwargs)
[
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,
].tap do |command|
command << "--minify" unless debug
command << "--postcss" if postcss
end
end

def watch_command(poll: false, **kwargs)
def watch_command(poll: false, postcss: false, **kwargs)
compile_command(**kwargs).tap do |command|
command << "-w"
command << "-p" if poll
command << "--postcss" if postcss
end
end
end
Expand Down
8 changes: 6 additions & 2 deletions lib/tasks/build.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace :tailwindcss do
desc "Build your Tailwind CSS"
task :build do |_, args|
debug = args.extras.include?("debug")
command = Tailwindcss::Commands.compile_command(debug: debug)
command = Tailwindcss::Commands.compile_command(debug: debug, postcss: use_postcss?)
puts command.inspect if args.extras.include?("verbose")
system(*command, exception: true)
end
Expand All @@ -11,10 +11,14 @@ namespace :tailwindcss do
task :watch do |_, args|
debug = args.extras.include?("debug")
poll = args.extras.include?("poll")
command = Tailwindcss::Commands.watch_command(debug: debug, poll: poll)
command = Tailwindcss::Commands.watch_command(debug: debug, poll: poll, postcss: use_postcss?)
puts command.inspect if args.extras.include?("verbose")
system(*command)
end

def use_postcss?
File.exist?(Rails.root.join("postcss.config.js"))
end
end

Rake::Task["assets:precompile"].enhance(["tailwindcss:build"])
Expand Down