
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
postcss-transform-tailwindcss
Advanced tools
[PostCSS Transform Tailwindcss] can convert class names from less, sass, and less files to classMame in tsx and class in html
[PostCSS Transform Tailwindcss] is a [PostCSS] plugin.
If you want to transition from semantic class names to Tailwindcss, this is a good tool.
postcss-transform-tailwindcss from npm.postcss-transform-tailwindcss to your configuration.
Read more on how to use and install PostCSS Transform Tailwindcss.Add [PostCSS Transform Tailwindcss] to your project:
npm install postcss-transform-tailwindcss --save-dev
Use [PostCSS Transform Tailwindcss] as a [PostCSS] plugin:
npm install sass --save-dev
npm install postcss-nested --save-dev
const sass = require("sass");
const postcss = require("postcss");
const postcssNested = require("postcss-nested");
const postcssTransformTailwindcss = require("postcss-transform-tailwindcss");
const from = "project/xxx/xxx.css";
const { css } = sass.compile();
postcss([
postcssNested(),
postcssTransformTailwindcss(/* pluginOptions */)
]).process(css, {
from,
to: undefined
});
npm install sass --save-dev
const sass = require("sass");
const postcss = require("postcss");
const postcssTransformTailwindcss = require("postcss-transform-tailwindcss");
const from = "project/xxx/xxx.scss";
const { css } = sass.compile();
postcss([postcssTransformTailwindcss(/* pluginOptions */)]).process(css, {
from,
to: undefined
});
npm install sass --save-dev
npm install less --save-dev
const sass = require("sass");
const postcss = require("postcss");
const postcssTransformTailwindcss = require("postcss-transform-tailwindcss");
const from = "project/xxx/xxx.less";
const css = fs.readFileSync(from, "utf-8");
// https://lesscss.org/usage/
less.render(css, async (error, output) => {
if (error) {
console.warn("error", error);
return;
}
const { css } = sass.compileString(output.css);
const result = await postcss([postcssTransformTailwindcss(opts)]).process(
css,
{
from,
to: undefined
}
);
});
npm install sass --save-dev
npm install less --save-dev
npm install globs --save-dev
const sass = require("sass");
const postcss = require("postcss");
const globs = require("globs");
const postcssTransformTailwindcss = require("postcss-transform-tailwindcss");
async function transformSass(from, opts = {}) {
const { css } = sass.compile(from);
const result = await postcss([postcssTransformTailwindcss(opts)]).process(
css,
{
from,
to: undefined
}
);
}
globs("xxx/xxx/**/*.scss", function(err, files) {
if (err) {
throw err;
}
files.forEach(path => {
transformSass(path, {
ratio: 2,
fileExtensions: ["tsx"],
removeEmptyClassName: true,
getClassNames(classNames, merge) {
classNames["align-items"] = merge(classNames["align-items"], {
"align-items: top;": "items-top",
"align-items: bottom;": "items-bottom"
});
return classNames;
}
});
});
});
The ratio option is similar to the ratio of the parameters in the Postcss-pxtransform plugin. For example, if the size is twice the size of the design draft, then ratio: 2.
postcssTransformTailwindcss({ ratio: 0 });
The FileExtensions option is a collection of files that CSS needs to convert, which can be of file types such as '.jsx ','.tsx', or '.html '
postcssTransformTailwindcss({ fileExtensions: ["jsx"] });
postcssTransformTailwindcss({ fileExtensions: ["jsx", "tsx"] });
postcssTransformTailwindcss({ fileExtensions: ["html", "tsx", "jsx"] });
The removeEmptyClassName option is very useful during debugging to determine whether to remove the class names of the corresponding. jsx, tsx,. html files that convert CSS
postcssTransformTailwindcss({ removeEmptyClassName: true });
The getClassNames option is a function that takes two parameters. The first parameter is a collection of tailwincss classNames, and the second parameter is [deepmerge]( https://www.npmjs.com/package/deepmerge )Method, you need to return the merged classNames
postcssTransformTailwindcss({
getClassNames(classNames, merge) {
classNames["align-items"] = merge(classNames["align-items"], {
"align-items: top;": "items-top",
"align-items: bottom;": "items-bottom"
});
return classNames;
}
});
FAQs
PostCSS plugin transform tailwincss
We found that postcss-transform-tailwindcss demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.