addBase will not work with vanilla class names #13840
Replies: 2 comments
-
I believe this works as designed. Tailwind only outputs class CSS rules if it sees the class name in any file content it is told to scan. In either version, the Thus, in the "broken" version, Comparatively, in the work-around, the You could consider one of:
|
Beta Was this translation helpful? Give feedback.
-
Hey! As @wongjn mentioned what you're seeing here is Tailwind only generating classes it detects are used. Few options:
const plugin = require('tailwindcss/plugin')
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{html,js}'],
theme: {
extend: {},
},
safelist: ['theme-1'],
plugins: [
plugin(({ addBase }) => {
addBase({
'.theme-1': {
color: 'red',
},
})
}),
],
}
const plugin = require('tailwindcss/plugin')
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{html,js}'],
theme: {
extend: {},
},
plugins: [
plugin(({ addBase }) => {
addBase({
'[class~="theme-1"]': {
color: 'red',
},
})
}),
],
}
@tailwind base;
.theme-1 {
color: red;
}
@tailwind components;
@tailwind utilities; I'd probably go with option 3 personally, no reason to use Tailwind's plugin system at all when you don't actually need the features of the plugin system. |
Beta Was this translation helpful? Give feedback.
-
What version of Tailwind CSS are you using?
3.4.4
What build tool (or framework if it abstracts the build tool) are you using?
Postcss, but my repro is using the tailwindcss cli
What version of Node.js are you using?
v18
What browser are you using?
N/A
What operating system are you using?
Windows/macOS
Reproduction URL
https://github.com/willwill96/tailwindcss-addBase-repro
Steps to reproduce:
npm install
npm run build:broken
for the broken versionnpm run build:working
for the working versionDescribe your issue
We are trying to use the
addBase
plugin to implement theming based on a parent class name, but it's not working, without a workaround.What does not work:
After generating the css (using
npm run build:broken
), note nothing referencing.theme-1
is present in theoutput.css
file.What does work (as a workaround):
After generating the css (using
npm run build:working
), note the following is present in theoutput.css
file:This has the end result we are looking for which is applying css based on a parent class name, however, it adds unnecessary css that ultimately does not get used.
Beta Was this translation helpful? Give feedback.
All reactions