Git Product home page Git Product logo

tailwindcss-rails's Introduction

Tailwind CSS for Rails

Tailwind CSS is a utility-first CSS framework packed with classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup.

Installation

With Rails 7 you can generate a new application preconfigured with Tailwind by using --css tailwind. If you're adding Tailwind later, you need to:

  1. Run ./bin/bundle add tailwindcss-rails
  2. Run ./bin/rails tailwindcss:install

This gem wraps the standalone executable version of the Tailwind CSS v3 framework. These executables are platform specific, so there are actually separate underlying gems per platform, but the correct gem will automatically be picked for your platform.

Supported platforms are:

  • arm64-darwin (macos-arm64)
  • x64-mingw32 (windows-x64)
  • x64-mingw-ucr (windows-x64)
  • x86_64-darwin (macos-x64)
  • x86_64-linux (linux-x64)
  • aarch64-linux (linux-arm64)
  • arm-linux (linux-armv7)

Using a local installation of tailwindcss

If you are not able to use the vendored standalone executables (for example, if you're on an unsupported platform), you can use a local installation of the tailwindcss executable by setting an environment variable named TAILWINDCSS_INSTALL_DIR to the directory path containing the executable.

For example, if you've installed tailwindcss so that the executable is found at /path/to/node_modules/bin/tailwindcss, then you should set your environment variable like so:

TAILWINDCSS_INSTALL_DIR=/path/to/node_modules/bin

or, for relative paths like ./node_modules/.bin/tailwindcss:

TAILWINDCSS_INSTALL_DIR=node_modules/.bin

Developing with Tailwindcss

Configuration and commands

Configuration file: config/tailwind.config.js

You can customize the Tailwind build through the config/tailwind.config.js file, just like you would if Tailwind was running in a traditional node installation. All the first-party plugins are supported.

Input file: app/assets/stylesheets/application.tailwind.css

The installer will generate a Tailwind input file in app/assets/stylesheets/application.tailwind.css. This is where you import the plugins you want to use, and where you can setup your custom @apply rules.

Output file: app/assets/builds/tailwind.css

When you run rails tailwindcss:build, the input file will be used to generate the output in app/assets/builds/tailwind.css. That's the output CSS that you'll include in your app (the installer automatically configures this, alongside the Inter font as well).

Commands

This gem makes several Rails tasks available, some of which have multiple options which can be combined.

Synopsis:

  • bin/rails tailwindcss:install - installs the configuration file, output file, and Procfile.dev
  • bin/rails tailwindcss:build - generate the output file
    • bin/rails tailwindcss:build[debug] - generate unminimized output
  • bin/rails tailwindcss:watch - start live rebuilds, generating output on file changes
    • bin/rails tailwindcss:watch[debug] - generate unminimized output
    • bin/rails tailwindcss:watch[poll] - for systems without file system events
    • bin/rails tailwindcss:watch[always] - for systems without TTY (e.g., some docker containers)

Note that you can combine task options, e.g. rails tailwindcss:watch[debug,poll].

This gem also makes available a Puma plugin to manage a live rebuild process when you run rails server (see "Live Rebuild" section below).

This gem also generates a Procfile.dev file which will run both the rails server and a live rebuild process (see "Live Rebuild" section below).

Building for production

The tailwindcss:build is automatically attached to assets:precompile, so before the asset pipeline digests the files, the Tailwind output will be generated.

Building for testing

The tailwindcss:build task is automatically attached to the test:prepare Rake task. This task runs before test commands. If you run bin/rails test in your CI environment, your Tailwind output will be generated before tests run.

Building 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].

Live rebuild

While you're developing your application, you want to run Tailwind in "watch" mode, so changes are automatically reflected in the generated CSS output. You can do this in a few different ways:

  • use this gem's Puma plugin to integrate "watch" with rails server,
  • or run rails tailwindcss:watch as a separate process,
  • or run bin/dev which uses Foreman

Puma plugin

This gem ships with a Puma plugin. To use it, add this line to your puma.rb configuration:

plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development"

and then running rails server will run the Tailwind watch process in the background

Run rails tailwindcss:watch

This is a flexible command, which can be run with a few different options.

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 to use the poll option.)

If you are running rails tailwindcss:watch as a process in a Docker container, set tty: true in docker-compose.yml for the appropriate container to keep the watch process running.

If you are running rails tailwindcss:watch in a docker container without a tty, pass the always argument to the task to instruct tailwindcss to keep the watcher alive even when stdin is closed: rails tailwindcss:watch[always]. If you use bin/dev then you should modify your Procfile.dev.

Foreman

Running bin/dev invokes Foreman to start both the Tailwind watch process and the rails server in development mode based on your Procfile.dev file.

Using with PostCSS

If you want to use PostCSS as a preprocessor, create a custom config/postcss.config.js and it will be loaded automatically.

For example, to enable nesting:

// config/postcss.config.js
module.exports = {
  plugins: {
    'postcss-import': {},
    'tailwindcss/nesting': {},
    tailwindcss: {},
    autoprefixer: {},
  },
}

Custom inputs or outputs

If you need to use a custom input or output file, you can run bundle exec tailwindcss to access the platform-specific executable, and give it your own build options.

Troubleshooting

Some common problems experienced by users ...

Lost keystrokes or hanging when using terminal-based debugging tools (e.g. IRB, Pry, ruby/debug...etc.) with the Puma plugin

We've addressed the issue and you can avoid the problem by upgrading tailwindcss-rails to v2.4.1 or later versions.

Running in a docker container exits prematurely

If you are running rails tailwindcss:watch as a process in a Docker container, set tty: true in docker-compose.yml for the appropriate container to keep the watch process running.

If you are running rails tailwindcss:watch in a docker container without a tty, pass the always argument to the task to instruct tailwindcss to keep the watcher alive even when stdin is closed: rails tailwindcss:watch[always]. If you use bin/dev then you should modify your Procfile.dev.

Conflict with sassc-rails

Tailwind uses modern CSS features that are not recognized by the sassc-rails extension that was included by default in the Gemfile for Rails 6. In order to avoid any errors like SassC::SyntaxError, you must remove that gem from your Gemfile.

Class names must be spelled out

For Tailwind to work, your class names need to be spelled out. If you need to make sure Tailwind generates class names that don't exist in your content files or that are programmatically composed, use the safelist option.

ERROR: Cannot find the tailwindcss executable for supported platform

Some users are reporting this error even when running on one of the supported native platforms:

  • arm64-darwin
  • x64-mingw32
  • x64-mingw-ucrt
  • x86_64-darwin
  • x86_64-linux
  • aarch64-linux

Check Bundler PLATFORMS

A possible cause of this is that Bundler has not been told to include native gems for your current platform. Please check your Gemfile.lock file to see whether your native platform is included in the PLATFORMS section. If necessary, run:

bundle lock --add-platform <platform-name>

and re-bundle.

Check BUNDLE_FORCE_RUBY_PLATFORM

Another common cause of this is that bundler is configured to always use the "ruby" platform via the BUNDLE_FORCE_RUBY_PLATFORM config parameter being set to true. Please remove this configuration:

bundle config unset force_ruby_platform
# or
bundle config set --local force_ruby_platform false

and re-bundle.

See https://bundler.io/man/bundle-config.1.html for more information.

Using asset-pipeline assets

In Rails, you want to use assets from the asset pipeline to get fingerprinting. However, Tailwind isn't aware of those assets.

To use assets from the pipeline, use url(image.svg). Since Sprockets v3.3.0 url(image.svg) is rewritten to /path/to/assets/image-7801e7538c6f1cc57aa75a5876ab0cac.svg so output CSS will have the correct path to those assets.

module.exports = {
    theme: {
        extend: {
            backgroundImage: {
                'image': "url('image.svg')"
            }
        }
    }
}

The inline version also works:

<section class="bg-[url('image.svg')]">Has the image as it's background</section>

Conflict with pre-existing asset pipeline stylesheets

If you get a warning Unrecognized at-rule or error parsing at-rule ‘@tailwind’. in the browser console after installation, you are incorrectly double-processing application.tailwind.css. This is a misconfiguration, even though the styles will be fully effective in many cases.

The file application.tailwind.css is installed when running rails tailwindcss:install and is placed alongside the common application.css in app/assets/stylesheets. Because the application.css in a newly generated Rails app includes a require_tree . directive, the asset pipeline incorrectly processes application.tailwind.css, where it should be taken care of by tailwindcss. The asset pipeline ignores TailwindCSS's at-directives, and the browser can't process them.

To fix the warning, you can either remove the application.css, if you don't plan to use the asset pipeline for stylesheets, and instead rely on TailwindCSS completely for styles. This is what this installer assumes.

Or, if you do want to keep using the asset pipeline in parallel, make sure to remove the require_tree . line from the application.css.

License

Tailwind for Rails is released under the MIT License. Tailwind CSS is released under the MIT License. The Inter font is released under the SIL Open Font License, Version 1.1.

tailwindcss-rails's People

Contributors

abhaynikam avatar bakivernes avatar blerchin avatar dependabot[bot] avatar dhh avatar dixpac avatar elia avatar emcoding avatar flavorjones avatar ghiculescu avatar jonathanhefner avatar joshmgross avatar kinsomicrote avatar lylo avatar m-nakamura145 avatar marcelkooi avatar marcoroth avatar mikerogers0 avatar npezza93 avatar olivierlacan avatar petergoldstein avatar pietmichal avatar rafaelfranca avatar rmacklin avatar rmehner avatar rolandstuder avatar schmidp avatar smeade avatar vinbarnes avatar weizheheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tailwindcss-rails's Issues

rails 7 scaffold system tests fail with -css tailwind

Reproduction instructions:

rm -rf foo
git clone git://github.com/rails/rails.git
./rails/railties/exe/rails new foo --css tailwind --edge
cd foo
rails generate scaffold book title
rails db:migrate
rails test:system

Expected results: tests pass

Actual results:

Error:
BooksTest#test_should_destroy_Book:
Capybara::ElementNotFound: Unable to find link or button "Destroy this book"
    test/system/books_test.rb:37:in `block in <class:BooksTest>'


rails test test/system/books_test.rb:35

...

Finished in 6.037822s, 0.6625 runs/s, 0.4969 assertions/s.
4 runs, 3 assertions, 0 failures, 1 errors, 0 skips

In tailwind, the show template uses the word Delete:

<%%= button_to 'Delete this <%= singular_table_name %>', <%= singular_table_name %>_path(@<%= singular_table_name %>), method: :delete, data: { confirm: "Are you sure you want to delete this <%= singular_table_name %>?" }, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>

In rails main, the show template use the word Destroy:

https://github.com/rails/rails/blob/2b6182cbd68231ed2a26417e3184c3d8ed21c57a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt#L9

Also in rails main, the system test template uses the word Destroy:

https://github.com/rails/rails/blob/2b6182cbd68231ed2a26417e3184c3d8ed21c57a/railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt#L48-L53

Either tailwindcss-rails needs to replace the system test template, or it needs to be consistent with the one provided by rails.

Webpacker not recompiling with new classes in production

Issue

Everything works fine in the development environment on my local machine. Online, however, some tailwind classes I have newly started using are missing from the emitted pack css file, even when I run rails webpacker:clobber and rails webpacker:compile again after deployment. No error appears in the deployment output.

I'm using this gem in version 0.3.3. The app is deployed on a VPS using dokku, which uses heroku buildpacks. The app is using webpacker, not the assets pipeline.

Files

postcss.config.js

let environment = {
  plugins: [
    require('autoprefixer'),
    require('tailwindcss')("./app/javascript/stylesheets/tailwind.config.js"),
	  require('postcss-import'),
    require('postcss-flexbugs-fixes'),
    require('postcss-preset-env')({
      autoprefixer: {
        flexbox: 'no-2009'
      },
      stage: 3
    })
  ]
}

module.exports = environment

app/javascript/stylesheets/tailwind.config.js

module.exports = {
  purge: [
    './app/**/*.html.erb',
    './app/helpers/**/*.rb',
    './app/javascript/**/*.js',
    './app/javascript/**/*.vue',
    './app/javascript/**/*.jsx',
  ],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}

config/webpacker.yml

# Note: You must restart bin/webpack-dev-server for changes to take effect

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_root_path: public
  public_output_path: packs
  cache_path: tmp/cache/webpacker
  webpack_compile_output: true

  # Additional paths webpack should lookup modules
  # ['app/assets', 'engine/foo/app/assets']
  additional_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  # Extract and emit a css file
  extract_css: false

  static_assets_extensions:
    - .jpg
    - .jpeg
    - .png
    - .gif
    - .tiff
    - .ico
    - .svg
    - .eot
    - .otf
    - .ttf
    - .woff
    - .woff2

  extensions:
    - .mjs
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    pretty: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: '**/node_modules/**'


test:
  <<: *default
  compile: true

  # Compile test packs to a separate directory
  public_output_path: packs-test

production:
  <<: *default

  # Production depends on precompilation of packs prior to booting for performance.
  compile: false

  # Extract and emit a css file
  extract_css: true

  # Cache manifest.json for performance
  cache_manifest: true

app/javascript/stylesheets/application.scss

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

// ...

app/javascript/packs/application.js

// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
import "channels"

Rails.start()
Turbolinks.start()
ActiveStorage.start()

require("stylesheets/application.scss")

import "controllers"

There is no purger in my production.rb

Hello,
After running rails tailwindcss:install there is no change in my production.rb file.
Can you help me about this? It says that

The last option adds the purger compressor to config/environments/production.rb

but there is no compressor enabled.

Should I add Tailwindcss::Purger.purge tailwind_css into my production.rb file

tailwind breaks rails mailer generator

With Rails 7.0.0.alpha2, running

rails new foo --css tailwind
cd foo
bin/rails generate mailer Order received shipped

Produces:

      create  app/mailers/order_mailer.rb
       error  tailwindcss [not found]
      invoke  test_unit
      create    test/mailers/order_mailer_test.rb
      create    test/mailers/previews/order_mailer_preview.rb

What's missing:

      invoke  erb
      create    app/views/order_mailer
      create    app/views/order_mailer/received.text.erb
      create    app/views/order_mailer/received.html.erb
      create    app/views/order_mailer/shipped.text.erb
      create    app/views/order_mailer/shipped.html.erb

Sprockets::Error: unknown compressor: purger in production

Hello,

After upgrading to Tailwindcss-Rails 2.0, re-running the install command and then deploying to production for the 1st time I encountered this error:

Sprockets::Error: unknown compressor: purger

Any advice on where I can look to try and find purger?

I'm deploying to Amazon Linux 2.

Thank you,

Binh

Dynamically-generated Class Names Getting Purged

Consider the following example function:

def style_for_btn_outline(color)
  "bg-transparent text-#{color}-500 border-#{color}-500 hover:bg-#{color}-500 hover:text-white"
end

When passed a color name, it generates a string of class names which can be appended to the class list for a button. If given the color "blue", it will generate the following string: bg-transparent text-blue-500 border-blue-500 hover:bg-blue-500 hover:text-white.

If the classes text-blue-500 border-blue-500 hover:bg-blue-500 are not used elsewhere in the project, the purger will remove them since they have not been explicitly specified.

As a quick hack for getting around this, I defined a constant like this:

module ApplicationHelper
  KEEP_THESE_CLASSES = 'text-blue-500 border-blue-500 hover:bg-blue-500'
end

While this is obviously not ideal, it works since it allows the purger to read those values and thus not purge them.

I could refactor the style_for_btn_outline method to something like this:

def style_for_btn_outline(color)
  case color
  when "red"
    "bg-transparent text-red-500 border-red-500 hover:bg-red-500 hover:text-white"
  when "blue"
     "bg-transparent text-blue-500 border-blue-500 hover:bg-blue-500 hover:text-white"
  end
end

Since I'm explicitly specifying the color classes per color, the purger keep the classes; I just need to repeat for each of the colors that I want to provide styles for.

But it seems like setting class names dynamically might be something that would make sense to want to do in certain instances. It feels like something that would be fairly natural to do.

What are your thoughts? Which of the two workarounds listed above makes the most sense in your opinion? Thanks for your time.

how to install on M1 (running in a container)

Let me start by apologizing for 'fuming in the wrong kitchen' (this is not tailwindcss-rails per se - I actually anticipate it doing exactly what it should! It's much more likely some Docker container "thing" that lures the container into reporting "aarch64-linux" which I -- by now -- have learned repeatedly, is not a supported architecture by tailwindcss-rails !

Reckoning me not being alone on this crusade I risk the barrage and go forth:

Question: Does anyone know how to get Rails 7.0.0 to install with TailwindCSS in containers on the Apple M1 ?

the sordid details

Apple's latest/finest 'sand' - the M1 - is screaming fast but somewhat of a challenge to run Docker containers on;

Like with the sparkling fresh Rails 7.0.0 when doing rails new . --css=tailwind

I have a Dockerfile like this

[ update: 2021-12-20 22:30 CEST: the from image is actually arm64v8/ruby ]

FROM arm64v8/ruby:3.03
#
# I took great inspiration in this work by [Will Schenk](https://willschenk.com/articles/2020/rails_in_docker/)
#

WORKDIR /app

COPY src/Gemfile /app/Gemfile
COPY src/Gemfile.lock /app/Gemfile.lock
RUN gem install bundler && bundle install


# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Configure the main process to run when running the image
CMD ["rails","server","-b","0.0.0.0"]

and a docker-compose.yml like this (the db part is merely for completeness - it serves no purpose in this trickery

#
# Most if not all of it is a blatant c/p from
# Will Schenk's https://willschenk.com/articles/2020/rails_in_docker/
#
version: "3.9"
services:
  db:
    build: mysql 
    platform: linux/x86_64
    image: mindling_db
    container_name: mindling_db
    command: [ "--default-authentication-plugin=mysql_native_password" ]
    ports:
      - "3306:3306"
    volumes:
      - ~/src/mysql_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: mindling_development
  mindling:
    platform: linux/arm64/v8
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - ./src:/app
    ports:
      - "3000:3000"
    depends_on:
      - db

When I let it 'rip' -- hoping to install tailwindcss goodness after the fact (it failed during the initial rails new too ) -- I get this sad reply:

√ mindling % x rails tailwindcss:install
Creating mindling_mindling_run ... done
Add Tailwindcss include tags and container element in application layout
File unchanged! The supplied flag value not found!  app/views/layouts/application.html.erb
File unchanged! The supplied flag value not found!  app/views/layouts/application.html.erb
File unchanged! The supplied flag value not found!  app/views/layouts/application.html.erb
Build into app/assets/builds
       exist  app/assets/builds
   identical  app/assets/builds/.keep
File unchanged! The supplied flag value not found!  app/assets/config/manifest.js
File unchanged! The supplied flag value not found!  .gitignore
File unchanged! The supplied flag value not found!  Procfile.dev
Add bin/dev to start foreman
   identical  bin/dev
Compile initial Tailwind build
         run  rails tailwindcss:build from "."
ERROR: tailwindcss-rails does not support the aarch64-linux platform
Please install tailwindcss following instructions at https://tailwindcss.com/docs/installation

but for some reason the container keeps 'bragging about being' aarch64-linux 😆

So - now my heading (and my bearing for that matter too) is somewhat lost!

How do I get my containers to swallow their (linux) pride and start behaving?

tailwindcss-rails raising SassC::SyntaxError

I am using gem 'tailwindcss-rails'

Layout:

    <%= stylesheet_link_tag "inter-font", "data-turbo-track": "reload" %>
    <%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>

Production:
config.assets.css_compressor = :purger

In circle ci it's raising a following error

rake aborted!
SassC::SyntaxError: Error: unterminated attribute selector for type
on line 1021:16 of stdin

.prose ol[type="A" s] {

---------------^
stdin:1021

Tailwind.config.js with asset pipeline

Thanks for providing this gem.

I can't seem to find documentation on how to customize Tailwind when using the asset pipeline.
I have a tailwind.config.js file in my rails root directory. Do I need to move the file to assets/javascripts/?

What's the proper way to do this?

Hover states not included after purge

Hover states works in development but not in production.

I use these hover states for a button hover:bg-green-600 hover:text-white hover:shadow-lg but when css is purged, these classes are not included.

In the tailwind.css file this is what hover:bg-green-600 looks like, so maybe it's due to structure of this, that the Purger doesn't work?

.hover\:bg-green-600:hover {
  --tw-bg-opacity: 1;
  background-color: rgba(5, 150, 105, var(--tw-bg-opacity));
}

Doesn't work on macOS (M1)

Hello,
I have created new rails app with --css tailwind flag.
Neither rails tailwindcss:build nor rails tailwindcss:watch produce any output and fail silently.
TailwindCSS executable doesn't seem to be installed with gem.

In my case command that is executed under the hood looks like this:
/Users/user/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/tailwindcss-rails-2.0.0/lib/tasks/../../exe/tailwindcss -i /Users/user/project/app/assets/stylesheets/application.tailwind.css -o /Users/user/project/app/assets/builds/tailwind.css -c /Users/user/project/config/tailwind.config.js

And when I try to execute it manually I get:
zsh: no such file or directory: /Users/user/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/tailwindcss-rails-2.0.0/lib/tasks/../../exe/tailwindcss

Expected compile speed ?

I'm getting ~7 seconds to compile an unaltered pipeline - is this typical as it severely impacts my workflow ?

My PC has a AMD Ryzen 9 3950X CPU - it's not a slow machine :|

Provide all first party plugins for the bundled Tailwind CSS

Hey everyone 👋

I was wondering if there was a reason to not include all of the first party plugins for the bundled tailwind.css. From what I can tell, these are the first party plugins that are not yet bundled:

  • Active
  • Group-focus
  • Motion-safe
  • Motion-reduce
  • Disable
  • Visited
  • Checked
  • First-child
  • Last-child
  • Odd-child
  • Even-child

I'm working on a new project without webpacker, and with these plugins, I can't think of anything else that would be missing.

Thanks!

What's the 2.0 strategy for including styles seen in engines?

The changes with Tailwind 3 mean that its server needs to know where all styles are to be found. How do we communicate that dynamically in the case of engine code?

Engine gems may be installed in multiple places, and in Ruby we can identify the filesystem location with MyEngine.root. In the prior release all we needed to do was not have them be purged which could be accomplished like this in production.rb:

  config.assets.css_compressor = Tailwindcss::Compressor.new(files_with_class_names:
    Rails.root.glob("app/views/**/*.*") +
    MyEngine::Engine.root.glob("app/views/**/*.*")
  )

Is there a supported strategy to communicate that in the tailwind.config.js file, which doesn't speak Ruby?

Or do we just need to generate that file with all locations added?

Anticipating Slow Compile Times

Hi there!

Very excited to see this package. Adding tailwind to a new rails project is one of the first things I do.

Locally, I've noticed that that a trivial change to application.js (or one of its dependencies) results in slow compile times:

[Webpacker] Compiling...
[Webpacker] Compiled all packs in /Users/evan/Projects/scratch-pad/TailwindTester/public/packs
[Webpacker] Hash: b937b4359523d601173a
Version: webpack 4.46.0
Time: 5188ms

This is on an M1 MBP.

This is a known issue for the interaction of postcss, web pack, and tailwind 2. While there are a few proposed work arounds on that issue, nothing seems super satisfactory.

Do you have any plans for addressing this? If so, I'd love to help in anyway. Right now I'm scratching my head on how to address it.

Release number to match the vendored version of Tailwind

I’d like to make a proposal that going forward the gem version matches the release of Tailwind vendored in the assets directory.

Doing so would make it far easier for users to determine what version of Tailwind they are using in the gem, and make bundle updates a breeze.

The gem is currently on version 0.3.3 and that vendors 2.0.2 of Tailwind.

Could we release 2.2.4 using this convention?



Huge fan Tailwind, thank you for all your work in making it so easy to use with the asset pipeline 😄

Rails 7: drop data: confirm from show template

When generating for rails 7, drop

data: { confirm: "Are you sure you want to delete this <%= singular_table_name %>?" }

from

<%%= button_to 'Destroy this <%= singular_table_name %>', <%= singular_table_name %>_path(@<%= singular_table_name %>), method: :delete, data: { confirm: "Are you sure you want to delete this <%= singular_table_name %>?" }, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>

Assets are never re-compiled

There seems to be a caching issue happening—assets:precompile does nothing even if new classes are used and purging needs to happen again. I have to run assets:clobber first to force a full re-compile.

Gem not compatible with rails 5+

The game is unfortunately only available for rails 6 since the installation command forces the app to use webpacker which is based on rails 6. since the gem is also working with the asset pipeline, it should be no problem to convert to 5+. is it planned to be available for rails 5, or is there a workaround to make it work?

After install can't build imported module

Hey,

I have two problems.

  1. When run ./bin/rails tailwindcss:install I have

Thor::Error: The file /Users/XXX/XXX/XXX/postcss.config.js does not appear to exist

I fixed this by adding manually postcss.config.js file in the root document with:

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}

I'm not sure if that's correct approach and not destroy the build.

  1. When refresh a page I receive all the time:
macroelements_type_controller.js:4 Uncaught Error: Module build failed: ModuleBuildError: Module build failed: 
@import "tailwindcss/base";
^
      File to import not found or unreadable: tailwindcss/base.
      in /Users/XXX/XXX/XXX/app/javascript/stylesheets/application.scss (line 1, column 1)

I can't find the reason of this bug. Any ideas how to fix this?

PS: macroelements_type_controller.js is a stimulus class and there is no connection between tailwind and this controller.

Webpack dev server doesn't work anymore

After following the installation steps, I cannot start webpack-dev-server anymore.
here's the stacktrace:

./bin/webpack-dev-server
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- /project/node_modules/webpack-dev-server/bin/webpack-dev-server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/project/node_modules/webpack-dev-server/bin/webpack-dev-server.js:65:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/project/node_modules/webpack-dev-server/bin/webpack-dev-server.js'
  ]
}

Ability to tweak Tailwind with its config file using PostCSS

In this repo's readme there's:

If you need to customize Tailwind, you will need to install it the traditional way using Webpacker instead

I see at the moment there's a hardcoded tailwind.css file in app/assets/stylesheets but in practice it's very common to want to customize Tailwind's fonts, color schemes, etc.. Especially so with Tailwind 2.0 because a lot of the color variants aren't enabled by default and you enable them by customizing the config.

I'm not sure how Tailwind works exactly under the hood but I think Tailwind is just a PostCSS plugin. The creator of Tailwind walks through creating a build step using PostCSS directly in this video https://egghead.io/lessons/tailwind-set-up-tailwind-and-postcss at the 4:04 to 4:49 mark. Basically after you modify your Tailwind config you would run that build step to generate a new tailwind.css file.

Do you foresee an an ability to allow users of this gem to customize Tailwind in the future by having this gem provide a rake task that lets you generate a custom tailwind.css file that uses PostCSS under the hood without the need for Webpacker?

I don't know what the limitations are around using PostCSS within the asset pipeline but if it's usable that would also mean you could use PostCSS plugins such as postcss-import, autoprefixer and also let Tailwind handle purging (it does this by default through PostCSS). I would love to be able to drop Webpacker.

Install fails on rails without webpack

When I run these steps:

rails new demo —database=postgresql --skip-jbuilder --skip-webpack-install
cd demo
./bin/bundle add tailwindcss-rails
./bin/rails tailwindcss:install

I get this error:

rails aborted!
Webpacker configuration file not found /Users/roeland/dev/demo/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/roeland/dev/demo/config/webpacker.yml
/Users/roeland/dev/demo/bin/rails:5:in `<top (required)>'
/Users/roeland/dev/demo/bin/spring:10:in `require'
/Users/roeland/dev/demo/bin/spring:10:in `block in <top (required)>'
/Users/roeland/dev/demo/bin/spring:7:in `<top (required)>'

Caused by:
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/roeland/dev/demo/config/webpacker.yml
/Users/roeland/dev/demo/bin/rails:5:in `<top (required)>'
/Users/roeland/dev/demo/bin/spring:10:in `require'
/Users/roeland/dev/demo/bin/spring:10:in `block in <top (required)>'
/Users/roeland/dev/demo/bin/spring:7:in `<top (required)>'
Tasks: TOP => app:template
(See full trace by running task with --trace)

I installed without webpack because of this in de README: When run on an app using the just the asset pipeline,

Purging classes using Webpacker in production

I'm not sure if I'm overlooking something very simple here, so please forgive me if that's the case, but I can't seem to work out how to purge classes during deployment to production using Webpacker. Would anybody please be so kind as to point me in the right direction? Thank you. 😄

Provide Webpack setup path

Like turbo-rails, it would be nice if this gem could double as an install script for Tailwind CSS on Webpack. If Webpack is detected, we run tailwindcss:install:webpack.

missing Tailwind CSS in production

Hey, thanks for the gem which was a breeze to use in development:

image

However in production the Tailwind CSS appears to be missing:

image

If I manually edit the production HTML and add a CDN-version of Tailwind, it looks fine. Am I missing a step to have production correctly pick up the assets?

From the README I thought it would be taken care of:

In development mode, the full 3mb+ Tailwind stylsheet is loaded, but in production, only the css classes used by files in app/views and app/helpers are included.

Recreate main customizations via erb

Adding font families or colors or additional spacings should be easily doable by turning the tailwind.css file into an erb where certain points of configuration can be generated at run-time. This would further shrink the number of Tailwind users needing to use the Webpack version.

Cannot run tailwindcss:install on 0.3.2

Hi!

The tailwindcss:install command fails on a fresh Rails 6.1.1 application, while using version 0.3.2.

./bin/rails tailwindcss:install
Copying Tailwindcss JavaScript
rails aborted!
Thor::Error: Could not find "/Users/marco.borromeo/.rvm/gems/ruby-2.7.1/gems/tailwindcss-rails-0.3.2/lib/install/app/assets/javascripts" in any of your source paths. Your current source paths are:
/Users/marco.borromeo/.rvm/gems/ruby-2.7.1/gems/railties-6.1.1/lib/rails/generators/rails/app/templates
/Users/marco.borromeo/temp/demo/bin/rails:5:in <top (required)>' /Users/marco.borromeo/temp/demo/bin/spring:10:in require'
/Users/marco.borromeo/temp/demo/bin/spring:10:in block in <top (required)>' /Users/marco.borromeo/temp/demo/bin/spring:7:in tap'
/Users/marco.borromeo/temp/demo/bin/spring:7:in <top (required)>' Tasks: TOP => app:template (See full trace by running task with --trace)

Downgrading to 0.3.1 perfectly works.

Purge also purges other stylesheets

I have Administrate installed, and the tailwdindcss-rails gem seems to also purge the CSS of Administrate. Seems like there is some kind of scoping needed to keep the purging to the tailwind css file.

Administrate.css without purge: https://gist.github.com/stephenson/6384c02f8645ae5d9977f3e1182935d4
Administrate.css with purge: https://gist.github.com/stephenson/284a7a93c87da5271684c95831e0eb1d

Any tricks or tips to fix? Would love to contribute, but sadly don't know where to start.

Let me know if there is anything I can do, if needed you can get access to the repo :)

Install broken without tailwind.config.js file?

The install script for this gem seems to require the presence of the tailwind.config.js file in app/javascript/stylesheets as referenced in the postcss.config.js file:

module.exports = {
  plugins: [
    require('tailwindcss')("./app/javascript/stylesheets/tailwind.config.js"),
    ...

However, the installer doesn't create this file. I'm not well versed with webpacker, postcss or js in general so I don't really understand what's going on here, but I do know the only way I could get my install to work was by adding the tailwind.config.js file.

Replacement ideas for @import

I'm not sure if this suggestion is out of scope for this gem, but I'm working on a project that is sorely missing the @import function of webpacker. There are certain instances where partials/view_components feel too heavy handed to accomplish what I want, such as for styling different elements as buttons or form inputs.

I've been experimenting with a helper that pulls the class names from a central config file that are scoped based on the parameter order. So my code looks like:

btn:
  base: 'inline-flex items-center ...'
  primary: 'bg-indigo-600 ...'

<%=button_tag 'Example', class: tailwind(:btn, :primary)%>

As you can probably guess, it uses the first parameter to scope the request, and combines any matches it finds within that scope. In my project, I have it always adding any base styles it finds within a scope. So in this case, it combines the btn > base and btn > primary class names.

This was the least verbose way I could think of to be able to make my smaller styles reusable. It's also great for referencing these styles as stimulus css classes.

Can anyone think of a better way of managing this without webpacker? Also, is this out of scope for what this gem wants to provide?

Missing documentation about tailwind.config.js customization

I was trying to customize Tailwind CSS via tailwind.config.js and looking for the proper way to do it I saw you wrote this:

When used with Webpacker, Tailwind CSS is installed as a postCSS processor. Refer to the TailwindCSS documentation to customize your tailwind.config.js file.

I followed all the steps in the Tailwind CSS documentation but I didn't get it to work so I made a little research and I found there're some additional steps to accomplish before it works with Rails.

Once you've installed the gem:

  • npx tailwindcss init
  • Move the recently created tailwind.config.js file somewhere inside your ./app/javascript folder in order the file to be packed for Rails (important).
  • Modify postcss.config.js to tell Webpacker where is the new file located: require('tailwindcss')('./app/javascript/tailwind.config.js'),
  • If you've copied the tailwind.config.js file from this repo, important to add the packages @tailwindcss/forms, @tailwindcss/aspect-ratio, @tailwindcss/typography to package.json and install.
  • Enjoy 🎉

The main problem I found was that Tailwind CSS documentation explains that the tailwind.config.js file is going to be searched (firstly) in the root of the project and currently in Rails this is definitely not going to happen.

I think this could be confusing and frustrating for people so maybe documentation should cover it as I guess customizing your Tailwind CSS boilerplate may be very common.

Doesn't work without sprockets

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?

Provide better defaults for the bundled Tailwind CSS

Tailwind UI documentation mentions some first-party plugins:

  • Include @tailwindcss/forms plugin (this provides a basic reset for form styles that makes form elements easy to override with utilities)
  • Include @tailwindcss/typography plugin (this gives utility classes like prose)
  • Include @tailwindcss/aspect-ratio plugin (this provides a composable API for giving elements a fixed aspect ratio)
  • Include Inter font

These change will make the default build a lot more useful.

group-hover classes are not removed

After 8af7bfc group-hover classes, group-hover:text-gray-900 for example, are not purged.

This adds a substantial amount of classes to the outputted css.

Unfortunately my regex skills are not strong enough to fix it.

(Originally created a comment but a new issue is probably more visible to people. )

Use @apply in custom scss?

Is there a way to import the tailwind into application.css/scss instead of the stylesheet_link_tag "tailwind" that would let us use @apply in the rest of our custom css? (No Webpacker)

Cannot find module @babel/compat-data/data/corejs3-shipped-proposals

After installing tailwindcss-rails and trying to compile with bin/rails webpacker:compile I get the following error:

ERROR in ./app/javascript/packs/application.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module '/home/kadu/sources/myapp/node_modules/@babel/compat-data/data/corejs3-shipped-proposals'
    at createEsmNotFoundErr (internal/modules/cjs/loader.js:842:15)
    at finalizeEsmResolution (internal/modules/cjs/loader.js:835:15)
    at resolveExports (internal/modules/cjs/loader.js:424:14)
    at Function.Module._findPath (internal/modules/cjs/loader.js:464:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:802:27)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (/home/kadu/sources/myapp/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/home/kadu/sources/myapp/node_modules/@babel/preset-env/lib/polyfills/corejs3/usage-plugin.js:10:55)
    at Module._compile (/home/kadu/sources/myapp/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (/home/kadu/sources/myapp/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/home/kadu/sources/myapp/node_modules/@babel/preset-env/lib/index.js:29:44)
    at Module._compile (/home/kadu/sources/myapp/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (/home/kadu/sources/myapp/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at requireModule (/home/kadu/sources/myapp/node_modules/@babel/core/lib/config/files/plugins.js:165:12)
    at loadPreset (/home/kadu/sources/myapp/node_modules/@babel/core/lib/config/files/plugins.js:83:17)
    at createDescriptor (/home/kadu/sources/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
    at /home/kadu/sources/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (/home/kadu/sources/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/home/kadu/sources/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at presets (/home/kadu/sources/myapp/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
    at mergeChainOpts (/home/kadu/sources/myapp/node_modules/@babel/core/lib/config/config-chain.js:320:26)
    at /home/kadu/sources/myapp/node_modules/@babel/core/lib/config/config-chain.js:283:7
    at Generator.next (<anonymous>)
    at buildRootChain (/home/kadu/sources/myapp/node_modules/@babel/core/lib/config/config-chain.js:90:27)
    at buildRootChain.next (<anonymous>)
    at loadPrivatePartialConfig (/home/kadu/sources/myapp/node_modules/@babel/core/lib/config/partial.js:95:62)

I tried with different versions of nodejs (15.10.0 and 12.21.0) with same results. I tried the solution presented in https://nodachisoft.com/common/en/article/en000018/#Solution and get another error:

EntryModuleNotFoundError: Entry module not found: Error: Can't resolve 'babel-loader' in '/home/kadu/sources/myapp'
    at /home/kadu/sources/myapp/node_modules/webpack/lib/Compilation.js:1075:31
    at /home/kadu/sources/myapp/node_modules/webpack/lib/NormalModuleFactory.js:401:22
    at /home/kadu/sources/myapp/node_modules/webpack/lib/NormalModuleFactory.js:130:21
    at /home/kadu/sources/myapp/node_modules/webpack/lib/NormalModuleFactory.js:337:24
    at /home/kadu/sources/myapp/node_modules/neo-async/async.js:2830:7
    at /home/kadu/sources/myapp/node_modules/neo-async/async.js:6877:13
    at /home/kadu/sources/myapp/node_modules/neo-async/async.js:2830:7
    at done (/home/kadu/sources/myapp/node_modules/neo-async/async.js:2925:13)
    at /home/kadu/sources/myapp/node_modules/webpack/lib/NormalModuleFactory.js:449:23
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:213:14
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/kadu/sources/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/kadu/sources/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/kadu/sources/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:25:1)
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/kadu/sources/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:25:1)
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/ModuleKindPlugin.js:30:40
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/kadu/sources/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/kadu/sources/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/forEachBail.js:30:14
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/kadu/sources/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/kadu/sources/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/kadu/sources/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:25:1)
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
    at /home/kadu/sources/myapp/node_modules/webpack/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/home/kadu/sources/myapp/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
resolve 'babel-loader' in '/home/kadu/sources/myapp'
  Parsed request is a module
  using description file: /home/kadu/sources/myapp/package.json (relative path: .)
    resolve as module
      /home/kadu/sources/bitcoin/node_modules doesn't exist or is not a directory
      /home/kadu/sources/node_modules doesn't exist or is not a directory
      /home/kadu/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /home/kadu/sources/myapp/node_modules
        using description file: /home/kadu/sources/myapp/package.json (relative path: ./node_modules)
          using description file: /home/kadu/sources/myapp/package.json (relative path: ./node_modules/babel-loader)
            no extension
              /home/kadu/sources/myapp/node_modules/babel-loader doesn't exist
            .js
              /home/kadu/sources/myapp/node_modules/babel-loader.js doesn't exist
            .json
              /home/kadu/sources/myapp/node_modules/babel-loader.json doesn't exist
            as directory
              /home/kadu/sources/myapp/node_modules/babel-loader doesn't exist

This is my package.json:

{
  "name": "myapp",
  "private": true,
  "dependencies": {
    "@hotwired/turbo-rails": "^7.0.0-beta.5",
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "4.2.2",
    "autoprefixer": "^9",
    "jquery": "^3.5.1",
    "popper.js": "^1.16.1",
    "postcss": "^7",
    "tailwindcss": "npm:@tailwindcss/postcss7-compat"
  },
  "version": "0.1.0",
  "devDependencies": {
    "webpack-dev-server": "^3.10.3"
  }
}

Any hint what I'm doing wrong and how we can avoid this problem for others?

Add app/javascript as default compressor folder to make a lookup

What?

Hi, first of all thanks for the work done here!

I was playing with importmaps and this gem to feel how is not to have any build step : ). Looks really nice. To try I made a dummy Rails app and when I deployed I was missing in Tailwind purged CSS a couple of classes.

I realized that's because app/javascript folder is not taken into consideration when doing the purging.

Is explained in the README how to add that folder and I did and it works
image

But I was wondering if it doesn't makes sense to include Javascript as default place to be purged. I'm all in in the Less javascript is better : ) But still I think is really rare if at some point you're not going to do some javascript and add/remove some CSS class.

Sorry if this is not that the right place to discuss this.
My thought was that this error can be hard to find for people without experience and adding app/javascript can make their life easier

Intellisense does not work with rails/tailwindcss-rails

👋 ,

This is more of a question than an issue. I've been toying around with https://github.com/rails/tailwindcss-rails the other day and while it's working perfectly fine, the VSCode extension does not work, since with this there is no tailwind entry in the package.json and also no tailwind config in the project root. It's all hidden within the gem.

I was wondering what the supposed escape hatch for this would be, do you have any ideas? Current workaround would be to replicate the config within the project root and add tailwind to the package.json, even though it's not used. Is there any other way?

Extract compressor as generic gem

Tailwind CSS needs purging, but it's a generic technique that could be used with any css toolkit. Should extract this into a generic gem. Maybe sprockets-css-purger, then this gem can use that, and focus mostly just on configuration and shipping the tailwind css.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.