diff --git a/Gemfile.lock b/Gemfile.lock index 384757b4..11f31dbd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,4 +100,4 @@ DEPENDENCIES tailwindcss-rails! BUNDLED WITH - 2.3.14 + 2.3.25 diff --git a/README.md b/README.md index db1a12cd..fb1279d4 100644 --- a/README.md +++ b/README.md @@ -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]`. @@ -147,6 +151,14 @@ The inline version also works:
Has the image as it's background
``` +### Contributing + +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). diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index e7f34cb5..e5d703a5 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -55,7 +55,7 @@ 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, @@ -63,13 +63,15 @@ def compile_command(debug: false, **kwargs) "-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 diff --git a/lib/tasks/build.rake b/lib/tasks/build.rake index bd407214..e3691670 100644 --- a/lib/tasks/build.rake +++ b/lib/tasks/build.rake @@ -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 @@ -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"])