Skip to content
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

Update for Tailwind CSS v4 #164

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

justalever
Copy link

@justalever justalever commented Jan 24, 2025

This is a pull request based on #163

Tailwind CSS v4 has new configurations that are simpler than v3 and prior.

Summary of changes:

  • Removes tailwind.config.js file
  • Swaps legacy @tailwind directives for normal @import "tailwindcss" support.
  • Uses npx and @tailwindcss/cli to build css
  • Updates README

Let me know if you see any red flags!

Tailwind CSS v4 comes with new configurations and build scripts. This updates the installer for Tailwind to include those changes.

say "Add build:css script"
add_package_json_script "build:css",
"tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
"npx @tailwindcss/cli -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
Copy link
Contributor

@navidemad navidemad Jan 25, 2025

Choose a reason for hiding this comment

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

It would be interesting to add to lib/install/helpers.rb something to support bun in order to use bunx/npx depending of what tools the user wanted to use.

  def bundler_x_cmd
    using_bun? ? "bunx" : "npx"
  end

Then you could do:

"#{bundler_x_cmd} @tailwindcss/cli -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good to me. I just added support in my latest commit #a0df0b7

@@ -2,6 +2,6 @@
"name": "app",
"private": "true",
"scripts": {
"build:css": "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css"
"build:css": "npx @tailwindcss/cli -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css"

Choose a reason for hiding this comment

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

Is it really necessary to run npx if you add @tailwindcss/cli as a depedency?
Also, would this also be a place to use bunx if using bun?

Copy link
Author

Choose a reason for hiding this comment

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

In my testing, something like npx or bunx is necessary to run the new @tailwindcss/cli package. The Tailwind docs have this, so I was going off that.

To be honest, I'm not sure this package.json file is necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is necessary because cssbundling-rails and jsbundling-rails are enhancing some rake tasks like precompile:assets to call this build and build:css task present in the package.json

Copy link
Author

Choose a reason for hiding this comment

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

@navidemad I mean the package.json file inside the lib/install/tailwind directory. I see no reference to it in rake tasks or elsewhere. I could be mistaken, of course.

@akimthedream
Copy link

Is there anything i can help with to advance with this PR? Is there anything missing? For me, all the changes are working. Hope to see rails new ... -css tailwind running smooth again soon 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants