Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
unplugin-tailwindcss-mangle
Advanced tools
mangle tailwindcss utilities class plugin. support vite and webpack!
mangle tailwindcss utilities plugin
It is recommended to read the documentation of tailwindcss-patch first, unplugin-tailwindcss-mangle
depends on this tool.
Now Support
vite
andwebpack
<!-- before -->
<div class="z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex"></div>
<!-- after -->
<div class="tw-g tw-h tw-i tw-d tw-e tw-j tw-k tw-l"></div>
<npm|yarn|pnpm> i -D unplugin-tailwindcss-mangle tailwindcss-patch
npx tw-patch install
prepare
script in your package.json
"scripts": {
"prepare": "tw-patch install"
},
cd to the same directory as package.json
and tailwind.config.js
, then run:
npx tw-patch extract
See more options in tailwindcss-patch
Then there will generate a json file: .tw-patch/tw-class-list.json
import vue from '@vitejs/plugin-vue'
import utwm from 'unplugin-tailwindcss-mangle/vite'
// for example: vue vite project
import { defineConfig } from 'vite'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(), utwm()]
})
then run script:
# generate bundle
yarn build
# preview
yarn preview
You will see all class was renamed to tw-*
// esm
import { webpackPlugin as utwm } from 'unplugin-tailwindcss-mangle'
// or cjs
const utwm = require('unplugin-tailwindcss-mangle/webpack')
// use this webpack plugin
// for example next.config.js
const { defineConfig } = require('@vue/cli-service')
// vue.config.js
module.exports = defineConfig({
transpileDependencies: true,
configureWebpack: (config) => {
if (process.env.NODE_ENV === 'production') {
config.plugins.push(utwm())
}
}
})
import nuxtPlugin from 'unplugin-tailwindcss-mangle/nuxt'
export default defineNuxtConfig({
// ...
// https://github.com/nuxt/nuxt/issues/20428
// you must set this option to false to enable vite extract css
experimental: {
inlineSSRStyles: false
},
modules: [
[
nuxtPlugin,
{
// options
}
]
]
})
By default, only the build will take effect. Due to some restrictions, it cannot take effect in the development mode.
This plugin only transform those classes which name contain -
or :
, like w-32
, before:h-[300px]
,after:dark:via-[#0141ff]/40
. some classes like flex
,relative
will not be mangled.
because plugin will traverse all html class attr
and js StringLiteral
to find utilities
generated by tailwindcss
.
it's dangerous to mangle some js StringLiteral
like:
const innerHTML = 'i\'m flex and relative and grid'
document.body.innerHTML = innerHTML
so only strings with -
or :
will be transformed.
// vite
- import { vitePlugin } from 'unplugin-tailwindcss-mangle'
+ import utwm from 'unplugin-tailwindcss-mangle/vite'
// webpack
- import { webpackPlugin } from 'unplugin-tailwindcss-mangle'
+ import utwm from 'unplugin-tailwindcss-mangle/webpack'
FAQs
mangle tailwindcss utilities class plugin. support vite and webpack!
The npm package unplugin-tailwindcss-mangle receives a total of 539 weekly downloads. As such, unplugin-tailwindcss-mangle popularity was classified as not popular.
We found that unplugin-tailwindcss-mangle demonstrated a healthy version release cadence and project activity because the last version was released less than 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.