We've moved discussions to Discord

Tailwind bg-color-number

Bryan Stewart
Hi everyone. not sure if you have seen this, but I cant seem to use most colors by bg on the page. I see that for some reason bg-red-400 works, but no other color. I am especially wanting to use gradients, etc.
Bryan Stewart
Chris Oliver  , do i need to recompile something to use the colors? None seem to be recognized. This is just development at this point
Mark Nelson
Did you see the post from Benjamin just below where Chris gave this advice: 
"You've also saved an HTML file with the class in it? It might just be getting purged."
This fixed the same problem for me.
Bryan Stewart
hey  Mark Nelson  ! Thanks for the reply. I havent overwritten those classes anywhere. Its pretty much stock JSP at this point.. Just trying to use the class
Mark Nelson
Hi Bryan, what I saw was that I could not dynamically change things like bg-color to my custom colors (or even standard colors), so for instance bg-gray-100 and some others would not work but bg-gray-700 did. What I understand happens is the purgeCSS utility removes colors that are not referenced somewhere in the html files in your app. I confirmed this by adding a custom class like "bg-lilac" to a <div>, restarting the server, and seeing the color used in a view. You can override this purceCSS behavior with a safelist option in Tailwind configuration (but this increases the CSS file size). This may be your problem.
Bryan Stewart
Mark Nelson I got excited for a min, because I changed a text div to use text-red-500 and it worked. Then all other numbers and color produced black or gray. I added this to my tailwind.config. Did I miss something? I have also restarted the server a few times. I have also tried text-red-800, text-red-200 and even text-secondary and all produce no change.
// See the Tailwind default theme values here:
// https://github.com/tailwindcss/tailwindcss/blob/master/stubs/defaultConfig.stub.js
const colors = require('tailwindcss/colors')
const defaultTheme = require('tailwindcss/defaultTheme')

module.exports = {
  plugins: [
    require('@tailwindcss/aspect-ratio'),
    require('@tailwindcss/forms')({ strategy: 'class' }),
    require('@tailwindcss/line-clamp'),
    require('@tailwindcss/typography'),
  ],

  content: [
    './app/helpers/**/*.rb',
    './app/javascript/**/*.js',
    './app/views/**/*.erb',
    './app/views/**/*.haml',
    './lib/jumpstart/app/views/**/*.erb',
    './lib/jumpstart/app/helpers/**/*.rb',
  ],
  options: {
	  safelist: [/(from|via|to|border|bg|text)-(.*)-(\\d{1}0{1,2})/]
  }

  // All the default values will be compiled unless they are overridden below
  theme: {
    // Extend (add to) the default theme in the `extend` key
    extend: {
		// Create your own at: https://javisperez.github.io/tailwindcolorshades
      
	  colors: {
        primary: colors.blue,
        secondary: colors.emerald,
        tertiary: colors.gray,
        danger: colors.red,
        "code-400": "#fefcf9",
        "code-600": "#3c455b",
      },
      fontFamily: {
        sans: ['Inter', ...defaultTheme.fontFamily.sans],
      },
    },
  },

  // Opt-in to TailwindCSS future changes
  future: {
  },
}
Mark Nelson
Your tailwind.config.js is the same as mine (except I have added custom colors after "code-600" and a serif font - which will not make any difference) but I do not have the options with the safelist which you should not need in development. I assume you have not made changes to the postcss.config.js or app/assets/stylesheets/application.tailwind.css files. If the configuration is not the issue then you can try things like rails assets:clean to remove old compiled assets (or even rails assets:clobber to remove all compiled assets - clobber will remove the public/assets directory in addition). I ran rails assets:clobber at one point myself. I am running Overmind which has yarn build:css --watch in the procfile and am on Rails 7.0.2.2 and Ruby 3.1.1. I know how frustrating these Tailwind issues are. The important thing is not to get stuck or discouraged - get on with something else and come back to this if necessary.
Bryan Stewart
Thanks for the feedback and options  Mark Nelson . I wholeheartedly agree with the move on approach. i will update the post with my findings.

Bryan Stewart
I clobbered the assets and was immediately able to see blue-500, then blue-200, changed to another and it stopped working again. 

I see this now. I did also try running rails. assets:precompile and restart the server. Yarn gave me a complaint about node incompatibility.. What is everyone using?

The asset "application.css" is not present in the asset pipeline.
Mark Nelson
I am using Yarn 1.22.17. You can just re-run yarn install and it should update and resolve any dependency issues (maybe brew upgrade as well before this). Not sure why you are getting the application.css message. The rails assets:precompile is for production deployment.
Notifications
You’re not receiving notifications from this thread.