New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

unplugin-tailwindcss-mangle

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unplugin-tailwindcss-mangle

mangle tailwindcss utilities class plugin. support vite and webpack!

  • 1.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
692
decreased by-9.07%
Maintainers
1
Weekly downloads
 
Created
Source

unplugin-tailwindcss-mangle

mangle tailwindcss utilities plugin

Now Support vite and webpack

Features

<!-- 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>

Usage

1. Install Package

<npm|yarn|pnpm> i -D unplugin-tailwindcss-mangle tailwindcss-patch

2. Run patch script

npx tw-patch

3. add prepare script in your package.json

  "scripts": {
    "prepare": "tw-patch"
  },

4. register this plugin

vite
// for example: vue vite project
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { vitePlugin as utwm } from 'unplugin-tailwindcss-mangle'
// 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-*

webpack
// esm
import { webpackPlugin as utwm } from 'unplugin-tailwindcss-mangle'
// or cjs
const { webpackPlugin: utwm } = require('unplugin-tailwindcss-mangle')
// use this webpack plugin
// for example next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  webpack: (config) => {
    config.plugins.push(utwm())
    return config
  }
}

module.exports = nextConfig

Options

classGenerator

custom class generator, if you want to custom class name (default 'tw-*'), use this options

export interface IClassGeneratorOptions {
  reserveClassName?: (string | RegExp)[]
  // custom generate class name
  customGenerate?: (original: string, opts: IClassGeneratorOptions, context: Record<string, any>) => string | undefined
  log?: boolean
  exclude?: (string | RegExp)[]
  include?: (string | RegExp)[]
  ignoreClass?: (string | RegExp)[]
  // default 'tw-',for example: tw-a,tw-b, you can set any you want, like '','ice-'
  classPrefix?: string
}

include / exclude

Type: string | string[]

Default: undefined

glob string allow you to control the mangle range of bundles.

Notice

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.

Keywords

FAQs

Package last updated on 07 Jun 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc