Skip to content

Doesn't work without sprockets #62

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
vfonic opened this issue Aug 9, 2021 · 10 comments
Closed

Doesn't work without sprockets #62

vfonic opened this issue Aug 9, 2021 · 10 comments

Comments

@vfonic
Copy link

vfonic commented Aug 9, 2021

I've just created a new rails app like this: rails new app_name --skip-sprockets

Then I ran the two commands:
./bin/bundle add tailwindcss-rails - worked fine
./bin/rails tailwindcss:install

This second command fails with:

NameError: uninitialized constant Tailwindcss::Engine::Sprockets

Since I'm planning on using Webpacker exclusively, I don't see the need for having to add Sprockets just to be able to use this gem. What do you think?

@vfonic
Copy link
Author

vfonic commented Aug 9, 2021

Confirmed. After I've uncommented require "sprockets/railtie" in config/application.rb, the installation succeeded.

@jasonplatts
Copy link

Hi @vfonic.

Unfortunately, that error is unrelated to the Tailwind CSS Nova extension, but instead is related to the tailwindcss-rails gem. If you submit an issue there, hopefully someone should be able to help. The Tailwind CSS Nova extension in no way relies on Sprockets.

Good luck!

Thanks,
Jason

@dhh
Copy link
Member

dhh commented Aug 9, 2021

This gem is designed to be used exclusively with the asset pipeline. It has no relevance for a Webpacker setup. You can just install Tailwind as normal for that.

@dhh dhh closed this as completed Aug 9, 2021
@vfonic
Copy link
Author

vfonic commented Aug 9, 2021

Perhaps that was true in the past, but it seems like the gem supports both Sprockets and Webpacker today.
As per README:

Tailwind CSS for Rails works with both the asset pipeline and Webpacker.

The install generator checks whether the app uses Sprockets or Webpacker:

https://github.com/rails/tailwindcss-rails/blob/main/lib/tasks/tailwindcss_tasks.rake#L3-L9

https://github.com/rails/tailwindcss-rails/blob/main/lib/tasks/tailwindcss_tasks.rake#L17-L20

Please reopen. Thanks!

@dhh
Copy link
Member

dhh commented Aug 9, 2021

Lol, yes, forgot we added that. Not sure it’s a good idea to have dual purpose like this, though.

@dhh dhh reopened this Aug 9, 2021
@vfonic
Copy link
Author

vfonic commented Aug 9, 2021

I understand. It's a tough call to make. I'd argue that, since the introduction of Webpacker, many gems have opted for the dual purpose/support. It's just the way things are now. I think having dual support makes more sense than having to maintain two separate gems that could have a lot of shared functionality (things like: purger, compressor, etc.)

@dhh
Copy link
Member

dhh commented Aug 9, 2021

Tailwind packed through Webpack has all those functions natively. This gem specifically implements those functions via Ruby for the asset pipeline. And then offers a slim, probably too-confusing wrapper on installing TW for Webpack.

@dixpac
Copy link
Contributor

dixpac commented Aug 14, 2021

@dhh I could do two things:

  1. Fix this issue and continue to support webpack
  2. Drop webpack support

I agree with your point that easiest way forward would be to just support asset pipeline and have one north star. Fix would include conditionals inside the engine.rb(or somekind of conditionals :))

require "tailwindcss/compressor" if defined?(Sprockets) # maybe also here

module Tailwindcss
  class Engine < ::Rails::Engine
    if defined?(Sprockets)
      ...
    end
  end
end

That being said I'm not gonna lie, spined-up numerous webpacker apps and this generator was helpful, but... :)


Main issue to use TW with asset pipeline is inability to use @apply out of the box. Every TW production app that I've worked with used @apply to extract common components such as button. Using @apply is maybe anti-pattern if we look at the TW idea, but without it some kind of componentization(view_component,partials) would be "necessary"

@dhh
Copy link
Member

dhh commented Aug 17, 2021

I think we should remove the webpack installer. This heart of this gem is a sprockets-specific approach to using TW with the asset pipeline. Let's just go with that.

Re: @apply, yes, I agree, would be nice to have a a sprockets version of this.

@dixpac
Copy link
Contributor

dixpac commented Aug 18, 2021

This is "fixed" here #64

@dhh dhh closed this as completed Aug 18, 2021
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

No branches or pull requests

4 participants