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 - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

333

./dist/index.js

@@ -6,234 +6,117 @@ 'use strict';

var unplugin$1 = require('unplugin');
var index = require('./index-2edd594b.js');
var parse5 = require('parse5');
var index$1 = require('./index-c8e1bdc5.js');
var micromatch = require('micromatch');
var fs = require('fs');
var path = require('path');
var fs = require('fs');
var tailwindcssMangleCore = require('tailwindcss-mangle-core');
var tailwindcssPatch = require('tailwindcss-patch');
require('@babel/types');
require('@babel/core');
require('micromatch');
require('postcss');
require('postcss-selector-parser');
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
var micromatch__default = /*#__PURE__*/_interopDefault(micromatch);
var fs__default = /*#__PURE__*/_interopDefault(fs);
var path__default = /*#__PURE__*/_interopDefault(path);
var fs__default = /*#__PURE__*/_interopDefault(fs);
({
HTML: parse5.html.NS.HTML,
XML: parse5.html.NS.XML,
MATHML: parse5.html.NS.MATHML,
SVG: parse5.html.NS.SVG,
XLINK: parse5.html.NS.XLINK,
XMLNS: parse5.html.NS.XMLNS
});
const pluginName = 'unplugin-tailwindcss-mangle';
/**
* Determines if a given node is a document or not
* @param {Node} node Node to test
* @return {boolean}
*/
function isDocument(node) {
return node.nodeName === '#document';
}
/**
* Determines if a given node is a document fragment or not
* @param {Node} node Node to test
* @return {boolean}
*/
function isDocumentFragment(node) {
return node.nodeName === '#document-fragment';
}
/**
* Determines if a given node is a template node or not
* @param {Node} node Node to test
* @return {boolean}
*/
function isTemplateNode(node) {
return node.nodeName === 'template';
}
const isElementNode = parse5.defaultTreeAdapter.isElementNode;
const isCommentNode = parse5.defaultTreeAdapter.isCommentNode;
const isDocumentTypeNode = parse5.defaultTreeAdapter.isDocumentTypeNode;
const isTextNode = parse5.defaultTreeAdapter.isTextNode;
/**
* Determines if a given node is a parent or not
* @param {Node} node Node to test
* @return {boolean}
*/
function isParentNode(node) {
return (isDocument(node) ||
isDocumentFragment(node) ||
isElementNode(node) ||
isTemplateNode(node));
}
parse5.defaultTreeAdapter.appendChild;
/**
* Traverses the tree of a given node
* @param {Node} node Node to traverse
* @param {Visitor} visitor Visitor to apply
* @param {ParentNode=} parent Parent node of the current node
* @return {void}
*/
function traverse(node, visitor, parent) {
const shouldVisitChildren = typeof visitor['pre:node'] !== 'function' ||
visitor['pre:node'](node, parent) !== false;
if (shouldVisitChildren && isParentNode(node)) {
for (const child of node.childNodes) {
traverse(child, visitor, node);
}
const { isMatch } = micromatch__default["default"];
const isMangleClass = (className) => {
return /[-:]/.test(className);
};
function groupBy(arr, cb) {
if (!Array.isArray(arr)) {
throw new Error('expected an array for first argument');
}
if (typeof visitor.node === 'function') {
visitor.node(node, parent);
if (typeof cb !== 'function') {
throw new Error('expected a function for second argument');
}
if (typeof visitor.document === 'function' && isDocument(node)) {
visitor.document(node);
}
if (typeof visitor.documentFragment === 'function' &&
isDocumentFragment(node)) {
visitor.documentFragment(node, parent);
}
if (typeof visitor.element === 'function' && isElementNode(node)) {
visitor.element(node, parent);
}
if (typeof visitor.template === 'function' && isTemplateNode(node)) {
visitor.template(node, parent);
}
if (typeof visitor.comment === 'function' && isCommentNode(node)) {
visitor.comment(node, parent);
}
if (typeof visitor.text === 'function' && isTextNode(node)) {
visitor.text(node, parent);
}
if (typeof visitor.documentType === 'function' && isDocumentTypeNode(node)) {
visitor.documentType(node, parent);
}
}
function htmlHandler(rawSource, options) {
const { runtimeSet, classGenerator } = options;
const fragment = parse5.parse(rawSource);
traverse(fragment, {
element(node, parent) {
const attr = node.attrs.find((x) => x.name === 'class');
if (attr) {
const arr = attr.value.split(/\s/).filter((x) => x);
attr.value = arr
.map((x) => {
if (runtimeSet.has(x)) {
return classGenerator.generateClassName(x).name;
}
return x;
})
.join(' ');
}
const result = {};
for (let i = 0; i < arr.length; i++) {
const item = arr[i];
const bucketCategory = cb(item);
const bucket = result[bucketCategory];
if (!Array.isArray(bucket)) {
result[bucketCategory] = [item];
}
});
return parse5.serialize(fragment);
}
class ClassGenerator {
newClassMap;
newClassSize;
context;
opts;
classPrefix;
constructor(opts = {}) {
this.newClassMap = {};
this.newClassSize = 0;
this.context = {};
this.opts = opts;
this.classPrefix = opts.classPrefix ?? 'tw-';
}
defaultClassGenerate() {
const chars = [];
let rest = (this.newClassSize - (this.newClassSize % index.acceptChars.length)) / index.acceptChars.length;
if (rest > 0) {
while (true) {
rest -= 1;
const m = rest % index.acceptChars.length;
const c = index.acceptChars[m];
chars.push(c);
rest -= m;
if (rest === 0) {
break;
}
rest /= index.acceptChars.length;
}
else {
result[bucketCategory].push(item);
}
const prefixIndex = this.newClassSize % index.acceptChars.length;
const newClassName = `${this.classPrefix}${index.acceptChars[prefixIndex]}${chars.join('')}`;
return newClassName;
}
ignoreClassName(className) {
return index.regExpTest(this.opts.ignoreClass, className);
return result;
}
function getGroupedEntries(entries, options = {
cssMatcher(file) {
return /\.css$/.test(file);
},
htmlMatcher(file) {
return /\.html?$/.test(file);
},
jsMatcher(file) {
return /\.[cm]?js$/.test(file);
}
includeFilePath(filePath) {
const { include } = this.opts;
if (Array.isArray(include)) {
return index.regExpTest(include, filePath);
}) {
const { cssMatcher, htmlMatcher, jsMatcher } = options;
const groupedEntries = groupBy(entries, ([file]) => {
if (cssMatcher(file)) {
return 'css';
}
else {
return true;
else if (htmlMatcher(file)) {
return 'html';
}
}
excludeFilePath(filePath) {
const { exclude } = this.opts;
if (Array.isArray(exclude)) {
return index.regExpTest(exclude, filePath);
else if (jsMatcher(file)) {
return 'js';
}
else {
return false;
return 'other';
}
});
if (!groupedEntries.css) {
groupedEntries.css = [];
}
isFileIncluded(filePath) {
return this.includeFilePath(filePath) && !this.excludeFilePath(filePath);
if (!groupedEntries.html) {
groupedEntries.html = [];
}
transformCssClass(className) {
const key = index.stripEscapeSequence(className);
const cn = this.newClassMap[key];
if (cn)
return cn.name;
return className;
if (!groupedEntries.js) {
groupedEntries.js = [];
}
generateClassName(original) {
const opts = this.opts;
original = index.stripEscapeSequence(original);
const cn = this.newClassMap[original];
if (cn)
return cn;
let newClassName;
if (opts.customGenerate && typeof opts.customGenerate === 'function') {
newClassName = opts.customGenerate(original, opts, this.context);
}
if (!newClassName) {
newClassName = this.defaultClassGenerate();
}
if (opts.reserveClassName && index.regExpTest(opts.reserveClassName, newClassName)) {
if (opts.log) {
console.log(`The class name has been reserved. ${newClassName}`);
}
this.newClassSize++;
return this.generateClassName(original);
}
if (opts.log) {
console.log(`Minify class name from ${original} to ${newClassName}`);
}
const newClass = {
name: newClassName,
usedBy: []
if (!groupedEntries.other) {
groupedEntries.other = [];
}
return groupedEntries;
}
function createGlobMatcher(pattern, fallbackValue = false) {
if (typeof pattern === 'undefined') {
return function (file) {
return fallbackValue;
};
this.newClassMap[original] = newClass;
this.newClassSize++;
return newClass;
}
return function (file) {
return isMatch(file, pattern);
};
}
function getCacheDir(basedir = process.cwd()) {
return path__default["default"].resolve(basedir, 'node_modules/.cache', pluginName);
}
function mkCacheDirectory(cwd = process.cwd()) {
const cacheDirectory = getCacheDir(cwd);
const exists = fs__default["default"].existsSync(cacheDirectory);
if (!exists) {
fs__default["default"].mkdirSync(cacheDirectory, {
recursive: true
});
}
return cacheDirectory;
}
function cacheDump(filename, data, basedir) {
try {
const dir = mkCacheDirectory(basedir);
fs__default["default"].writeFileSync(path__default["default"].resolve(dir, filename), JSON.stringify(Array.from(data), null, 2), 'utf-8');
}
catch (error) {
console.log(error);
}
}
function getOptions(options = {}) {
const includeMatcher = index.createGlobMatcher(options.include, true);
const excludeMatcher = index.createGlobMatcher(options.exclude, false);
const includeMatcher = createGlobMatcher(options.include, true);
const excludeMatcher = createGlobMatcher(options.exclude, false);
function isInclude(file) {

@@ -257,3 +140,3 @@ return includeMatcher(file) && !excludeMatcher(file);

}
const classGenerator = new ClassGenerator(options.classGenerator);
const classGenerator = new tailwindcssMangleCore.ClassGenerator(options.classGenerator);
function getCachedClassSet() {

@@ -263,6 +146,6 @@ const set = twPatcher.getClassSet();

if (isOutput && classSetOutputOptions.type === 'all') {
index.cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
}
set.forEach((c) => {
if (!index.isMangleClass(c)) {
if (!isMangleClass(c)) {
set.delete(c);

@@ -272,3 +155,3 @@ }

if (isOutput && classSetOutputOptions.type === 'partial') {
index.cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
}

@@ -294,3 +177,3 @@ classSet = set;

return {
name: index.pluginName,
name: pluginName,
enforce: 'post',

@@ -304,3 +187,3 @@ vite: {

}
const groupedEntries = index.getGroupedEntries(Object.entries(bundle));
const groupedEntries = getGroupedEntries(Object.entries(bundle));
if (Array.isArray(groupedEntries.html) && groupedEntries.html.length) {

@@ -310,3 +193,3 @@ for (let i = 0; i < groupedEntries.html.length; i++) {

if (isInclude(file)) {
asset.source = htmlHandler(asset.source.toString(), {
asset.source = tailwindcssMangleCore.htmlHandler(asset.source.toString(), {
classGenerator,

@@ -322,3 +205,3 @@ runtimeSet

if (isInclude(file)) {
const code = index.jsHandler(chunk.code, {
const code = tailwindcssMangleCore.jsHandler(chunk.code, {
runtimeSet,

@@ -337,3 +220,3 @@ classGenerator

if (isInclude(file)) {
css.source = index$1.cssHandler(css.source.toString(), {
css.source = tailwindcssMangleCore.cssHandler(css.source.toString(), {
classGenerator,

@@ -368,4 +251,4 @@ runtimeSet

const twmCssloader = path__default["default"].resolve(__dirname, 'twm-css.js');
compiler.hooks.compilation.tap(index.pluginName, (compilation) => {
NormalModule.getCompilationHooks(compilation).loader.tap(index.pluginName, (loaderContext, module) => {
compiler.hooks.compilation.tap(pluginName, (compilation) => {
NormalModule.getCompilationHooks(compilation).loader.tap(pluginName, (loaderContext, module) => {
const idx = module.loaders.findIndex((x) => x.loader.includes('css-loader'));

@@ -385,7 +268,7 @@ if (idx > -1) {

compilation.hooks.processAssets.tap({
name: index.pluginName,
name: pluginName,
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
}, (assets) => {
const runtimeSet = getCachedClassSet();
const groupedEntries = index.getGroupedEntries(Object.entries(assets));
const groupedEntries = getGroupedEntries(Object.entries(assets));
if (!runtimeSet.size) {

@@ -417,3 +300,3 @@ const css = new Map();

if (isInclude(file)) {
const html = htmlHandler(asset.source().toString(), {
const html = tailwindcssMangleCore.htmlHandler(asset.source().toString(), {
classGenerator,

@@ -431,3 +314,3 @@ runtimeSet

if (isInclude(file)) {
const code = index.jsHandler(chunk.source().toString(), {
const code = tailwindcssMangleCore.jsHandler(chunk.source().toString(), {
runtimeSet,

@@ -447,3 +330,3 @@ classGenerator

if (isInclude(file)) {
const newCss = index$1.cssHandler(css.source().toString(), {
const newCss = tailwindcssMangleCore.cssHandler(css.source().toString(), {
classGenerator,

@@ -461,3 +344,3 @@ runtimeSet

if (isInclude(file)) {
const html = htmlHandler(asset.source().toString(), {
const html = tailwindcssMangleCore.htmlHandler(asset.source().toString(), {
classGenerator,

@@ -475,3 +358,3 @@ runtimeSet

const rawCode = chunk.source().toString();
const code = index.jsHandler(rawCode, {
const code = tailwindcssMangleCore.jsHandler(rawCode, {
runtimeSet,

@@ -490,3 +373,3 @@ classGenerator

if (isInclude(file)) {
const newCss = index$1.cssHandler(style.source().toString(), {
const newCss = tailwindcssMangleCore.cssHandler(style.source().toString(), {
classGenerator,

@@ -507,3 +390,3 @@ runtimeSet

if (entries.length && classMapOutputOptions) {
index.cacheDump(classMapOutputOptions.filename, entries.map((x) => {
cacheDump(classMapOutputOptions.filename, entries.map((x) => {
return [x[0], x[1].name];

@@ -510,0 +393,0 @@ }), classMapOutputOptions.dir);

@@ -5,12 +5,6 @@ 'use strict';

require('unplugin');
require('./index-2edd594b.js');
require('@babel/types');
require('@babel/core');
require('micromatch');
require('fs');
require('path');
require('parse5');
require('./index-c8e1bdc5.js');
require('postcss');
require('postcss-selector-parser');
require('tailwindcss-mangle-core');
require('tailwindcss-patch');

@@ -17,0 +11,0 @@

@@ -6,234 +6,117 @@ 'use strict';

var unplugin$1 = require('unplugin');
var index = require('./index-2edd594b.js');
var parse5 = require('parse5');
var index$1 = require('./index-c8e1bdc5.js');
var micromatch = require('micromatch');
var fs = require('fs');
var path = require('path');
var fs = require('fs');
var tailwindcssMangleCore = require('tailwindcss-mangle-core');
var tailwindcssPatch = require('tailwindcss-patch');
require('@babel/types');
require('@babel/core');
require('micromatch');
require('postcss');
require('postcss-selector-parser');
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
var micromatch__default = /*#__PURE__*/_interopDefault(micromatch);
var fs__default = /*#__PURE__*/_interopDefault(fs);
var path__default = /*#__PURE__*/_interopDefault(path);
var fs__default = /*#__PURE__*/_interopDefault(fs);
({
HTML: parse5.html.NS.HTML,
XML: parse5.html.NS.XML,
MATHML: parse5.html.NS.MATHML,
SVG: parse5.html.NS.SVG,
XLINK: parse5.html.NS.XLINK,
XMLNS: parse5.html.NS.XMLNS
});
const pluginName = 'unplugin-tailwindcss-mangle';
/**
* Determines if a given node is a document or not
* @param {Node} node Node to test
* @return {boolean}
*/
function isDocument(node) {
return node.nodeName === '#document';
}
/**
* Determines if a given node is a document fragment or not
* @param {Node} node Node to test
* @return {boolean}
*/
function isDocumentFragment(node) {
return node.nodeName === '#document-fragment';
}
/**
* Determines if a given node is a template node or not
* @param {Node} node Node to test
* @return {boolean}
*/
function isTemplateNode(node) {
return node.nodeName === 'template';
}
const isElementNode = parse5.defaultTreeAdapter.isElementNode;
const isCommentNode = parse5.defaultTreeAdapter.isCommentNode;
const isDocumentTypeNode = parse5.defaultTreeAdapter.isDocumentTypeNode;
const isTextNode = parse5.defaultTreeAdapter.isTextNode;
/**
* Determines if a given node is a parent or not
* @param {Node} node Node to test
* @return {boolean}
*/
function isParentNode(node) {
return (isDocument(node) ||
isDocumentFragment(node) ||
isElementNode(node) ||
isTemplateNode(node));
}
parse5.defaultTreeAdapter.appendChild;
/**
* Traverses the tree of a given node
* @param {Node} node Node to traverse
* @param {Visitor} visitor Visitor to apply
* @param {ParentNode=} parent Parent node of the current node
* @return {void}
*/
function traverse(node, visitor, parent) {
const shouldVisitChildren = typeof visitor['pre:node'] !== 'function' ||
visitor['pre:node'](node, parent) !== false;
if (shouldVisitChildren && isParentNode(node)) {
for (const child of node.childNodes) {
traverse(child, visitor, node);
}
const { isMatch } = micromatch__default["default"];
const isMangleClass = (className) => {
return /[-:]/.test(className);
};
function groupBy(arr, cb) {
if (!Array.isArray(arr)) {
throw new Error('expected an array for first argument');
}
if (typeof visitor.node === 'function') {
visitor.node(node, parent);
if (typeof cb !== 'function') {
throw new Error('expected a function for second argument');
}
if (typeof visitor.document === 'function' && isDocument(node)) {
visitor.document(node);
}
if (typeof visitor.documentFragment === 'function' &&
isDocumentFragment(node)) {
visitor.documentFragment(node, parent);
}
if (typeof visitor.element === 'function' && isElementNode(node)) {
visitor.element(node, parent);
}
if (typeof visitor.template === 'function' && isTemplateNode(node)) {
visitor.template(node, parent);
}
if (typeof visitor.comment === 'function' && isCommentNode(node)) {
visitor.comment(node, parent);
}
if (typeof visitor.text === 'function' && isTextNode(node)) {
visitor.text(node, parent);
}
if (typeof visitor.documentType === 'function' && isDocumentTypeNode(node)) {
visitor.documentType(node, parent);
}
}
function htmlHandler(rawSource, options) {
const { runtimeSet, classGenerator } = options;
const fragment = parse5.parse(rawSource);
traverse(fragment, {
element(node, parent) {
const attr = node.attrs.find((x) => x.name === 'class');
if (attr) {
const arr = attr.value.split(/\s/).filter((x) => x);
attr.value = arr
.map((x) => {
if (runtimeSet.has(x)) {
return classGenerator.generateClassName(x).name;
}
return x;
})
.join(' ');
}
const result = {};
for (let i = 0; i < arr.length; i++) {
const item = arr[i];
const bucketCategory = cb(item);
const bucket = result[bucketCategory];
if (!Array.isArray(bucket)) {
result[bucketCategory] = [item];
}
});
return parse5.serialize(fragment);
}
class ClassGenerator {
newClassMap;
newClassSize;
context;
opts;
classPrefix;
constructor(opts = {}) {
this.newClassMap = {};
this.newClassSize = 0;
this.context = {};
this.opts = opts;
this.classPrefix = opts.classPrefix ?? 'tw-';
}
defaultClassGenerate() {
const chars = [];
let rest = (this.newClassSize - (this.newClassSize % index.acceptChars.length)) / index.acceptChars.length;
if (rest > 0) {
while (true) {
rest -= 1;
const m = rest % index.acceptChars.length;
const c = index.acceptChars[m];
chars.push(c);
rest -= m;
if (rest === 0) {
break;
}
rest /= index.acceptChars.length;
}
else {
result[bucketCategory].push(item);
}
const prefixIndex = this.newClassSize % index.acceptChars.length;
const newClassName = `${this.classPrefix}${index.acceptChars[prefixIndex]}${chars.join('')}`;
return newClassName;
}
ignoreClassName(className) {
return index.regExpTest(this.opts.ignoreClass, className);
return result;
}
function getGroupedEntries(entries, options = {
cssMatcher(file) {
return /\.css$/.test(file);
},
htmlMatcher(file) {
return /\.html?$/.test(file);
},
jsMatcher(file) {
return /\.[cm]?js$/.test(file);
}
includeFilePath(filePath) {
const { include } = this.opts;
if (Array.isArray(include)) {
return index.regExpTest(include, filePath);
}) {
const { cssMatcher, htmlMatcher, jsMatcher } = options;
const groupedEntries = groupBy(entries, ([file]) => {
if (cssMatcher(file)) {
return 'css';
}
else {
return true;
else if (htmlMatcher(file)) {
return 'html';
}
}
excludeFilePath(filePath) {
const { exclude } = this.opts;
if (Array.isArray(exclude)) {
return index.regExpTest(exclude, filePath);
else if (jsMatcher(file)) {
return 'js';
}
else {
return false;
return 'other';
}
});
if (!groupedEntries.css) {
groupedEntries.css = [];
}
isFileIncluded(filePath) {
return this.includeFilePath(filePath) && !this.excludeFilePath(filePath);
if (!groupedEntries.html) {
groupedEntries.html = [];
}
transformCssClass(className) {
const key = index.stripEscapeSequence(className);
const cn = this.newClassMap[key];
if (cn)
return cn.name;
return className;
if (!groupedEntries.js) {
groupedEntries.js = [];
}
generateClassName(original) {
const opts = this.opts;
original = index.stripEscapeSequence(original);
const cn = this.newClassMap[original];
if (cn)
return cn;
let newClassName;
if (opts.customGenerate && typeof opts.customGenerate === 'function') {
newClassName = opts.customGenerate(original, opts, this.context);
}
if (!newClassName) {
newClassName = this.defaultClassGenerate();
}
if (opts.reserveClassName && index.regExpTest(opts.reserveClassName, newClassName)) {
if (opts.log) {
console.log(`The class name has been reserved. ${newClassName}`);
}
this.newClassSize++;
return this.generateClassName(original);
}
if (opts.log) {
console.log(`Minify class name from ${original} to ${newClassName}`);
}
const newClass = {
name: newClassName,
usedBy: []
if (!groupedEntries.other) {
groupedEntries.other = [];
}
return groupedEntries;
}
function createGlobMatcher(pattern, fallbackValue = false) {
if (typeof pattern === 'undefined') {
return function (file) {
return fallbackValue;
};
this.newClassMap[original] = newClass;
this.newClassSize++;
return newClass;
}
return function (file) {
return isMatch(file, pattern);
};
}
function getCacheDir(basedir = process.cwd()) {
return path__default["default"].resolve(basedir, 'node_modules/.cache', pluginName);
}
function mkCacheDirectory(cwd = process.cwd()) {
const cacheDirectory = getCacheDir(cwd);
const exists = fs__default["default"].existsSync(cacheDirectory);
if (!exists) {
fs__default["default"].mkdirSync(cacheDirectory, {
recursive: true
});
}
return cacheDirectory;
}
function cacheDump(filename, data, basedir) {
try {
const dir = mkCacheDirectory(basedir);
fs__default["default"].writeFileSync(path__default["default"].resolve(dir, filename), JSON.stringify(Array.from(data), null, 2), 'utf-8');
}
catch (error) {
console.log(error);
}
}
function getOptions(options = {}) {
const includeMatcher = index.createGlobMatcher(options.include, true);
const excludeMatcher = index.createGlobMatcher(options.exclude, false);
const includeMatcher = createGlobMatcher(options.include, true);
const excludeMatcher = createGlobMatcher(options.exclude, false);
function isInclude(file) {

@@ -257,3 +140,3 @@ return includeMatcher(file) && !excludeMatcher(file);

}
const classGenerator = new ClassGenerator(options.classGenerator);
const classGenerator = new tailwindcssMangleCore.ClassGenerator(options.classGenerator);
function getCachedClassSet() {

@@ -263,6 +146,6 @@ const set = twPatcher.getClassSet();

if (isOutput && classSetOutputOptions.type === 'all') {
index.cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
}
set.forEach((c) => {
if (!index.isMangleClass(c)) {
if (!isMangleClass(c)) {
set.delete(c);

@@ -272,3 +155,3 @@ }

if (isOutput && classSetOutputOptions.type === 'partial') {
index.cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
}

@@ -294,3 +177,3 @@ classSet = set;

return {
name: index.pluginName,
name: pluginName,
enforce: 'post',

@@ -304,3 +187,3 @@ vite: {

}
const groupedEntries = index.getGroupedEntries(Object.entries(bundle));
const groupedEntries = getGroupedEntries(Object.entries(bundle));
if (Array.isArray(groupedEntries.html) && groupedEntries.html.length) {

@@ -310,3 +193,3 @@ for (let i = 0; i < groupedEntries.html.length; i++) {

if (isInclude(file)) {
asset.source = htmlHandler(asset.source.toString(), {
asset.source = tailwindcssMangleCore.htmlHandler(asset.source.toString(), {
classGenerator,

@@ -322,3 +205,3 @@ runtimeSet

if (isInclude(file)) {
const code = index.jsHandler(chunk.code, {
const code = tailwindcssMangleCore.jsHandler(chunk.code, {
runtimeSet,

@@ -337,3 +220,3 @@ classGenerator

if (isInclude(file)) {
css.source = index$1.cssHandler(css.source.toString(), {
css.source = tailwindcssMangleCore.cssHandler(css.source.toString(), {
classGenerator,

@@ -368,4 +251,4 @@ runtimeSet

const twmCssloader = path__default["default"].resolve(__dirname, 'twm-css.js');
compiler.hooks.compilation.tap(index.pluginName, (compilation) => {
NormalModule.getCompilationHooks(compilation).loader.tap(index.pluginName, (loaderContext, module) => {
compiler.hooks.compilation.tap(pluginName, (compilation) => {
NormalModule.getCompilationHooks(compilation).loader.tap(pluginName, (loaderContext, module) => {
const idx = module.loaders.findIndex((x) => x.loader.includes('css-loader'));

@@ -385,7 +268,7 @@ if (idx > -1) {

compilation.hooks.processAssets.tap({
name: index.pluginName,
name: pluginName,
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
}, (assets) => {
const runtimeSet = getCachedClassSet();
const groupedEntries = index.getGroupedEntries(Object.entries(assets));
const groupedEntries = getGroupedEntries(Object.entries(assets));
if (!runtimeSet.size) {

@@ -417,3 +300,3 @@ const css = new Map();

if (isInclude(file)) {
const html = htmlHandler(asset.source().toString(), {
const html = tailwindcssMangleCore.htmlHandler(asset.source().toString(), {
classGenerator,

@@ -431,3 +314,3 @@ runtimeSet

if (isInclude(file)) {
const code = index.jsHandler(chunk.source().toString(), {
const code = tailwindcssMangleCore.jsHandler(chunk.source().toString(), {
runtimeSet,

@@ -447,3 +330,3 @@ classGenerator

if (isInclude(file)) {
const newCss = index$1.cssHandler(css.source().toString(), {
const newCss = tailwindcssMangleCore.cssHandler(css.source().toString(), {
classGenerator,

@@ -461,3 +344,3 @@ runtimeSet

if (isInclude(file)) {
const html = htmlHandler(asset.source().toString(), {
const html = tailwindcssMangleCore.htmlHandler(asset.source().toString(), {
classGenerator,

@@ -475,3 +358,3 @@ runtimeSet

const rawCode = chunk.source().toString();
const code = index.jsHandler(rawCode, {
const code = tailwindcssMangleCore.jsHandler(rawCode, {
runtimeSet,

@@ -490,3 +373,3 @@ classGenerator

if (isInclude(file)) {
const newCss = index$1.cssHandler(style.source().toString(), {
const newCss = tailwindcssMangleCore.cssHandler(style.source().toString(), {
classGenerator,

@@ -507,3 +390,3 @@ runtimeSet

if (entries.length && classMapOutputOptions) {
index.cacheDump(classMapOutputOptions.filename, entries.map((x) => {
cacheDump(classMapOutputOptions.filename, entries.map((x) => {
return [x[0], x[1].name];

@@ -510,0 +393,0 @@ }), classMapOutputOptions.dir);

import * as webpack from 'webpack';
import ClassGenerator from '../classGenerator';
import { ClassGenerator } from 'tailwindcss-mangle-core';
export default function cssloader(this: webpack.LoaderContext<{

@@ -4,0 +4,0 @@ classGenerator: ClassGenerator;

@@ -5,12 +5,6 @@ 'use strict';

require('unplugin');
require('./index-2edd594b.js');
require('@babel/types');
require('@babel/core');
require('micromatch');
require('fs');
require('path');
require('parse5');
require('./index-c8e1bdc5.js');
require('postcss');
require('postcss-selector-parser');
require('tailwindcss-mangle-core');
require('tailwindcss-patch');

@@ -17,0 +11,0 @@

import type { Options, ClassSetOutputOptions, ClassMapOutputOptions } from './types';
import { TailwindcssPatcher } from 'tailwindcss-patch';
import ClassGenerator from './classGenerator';
import { ClassGenerator } from 'tailwindcss-mangle-core';
export declare function getOptions(options?: Options | undefined): {

@@ -5,0 +5,0 @@ getCachedClassSet: () => Set<string>;

@@ -5,12 +5,6 @@ 'use strict';

require('unplugin');
require('./index-2edd594b.js');
require('@babel/types');
require('@babel/core');
require('micromatch');
require('fs');
require('path');
require('parse5');
require('./index-c8e1bdc5.js');
require('postcss');
require('postcss-selector-parser');
require('tailwindcss-mangle-core');
require('tailwindcss-patch');

@@ -17,0 +11,0 @@

'use strict';
var index = require('./index-c8e1bdc5.js');
require('postcss');
require('postcss-selector-parser');
var tailwindcssMangleCore = require('tailwindcss-mangle-core');

@@ -12,3 +10,3 @@ function cssloader(content) {

const runtimeSet = opt.getCachedClassSet();
return index.cssHandler(content, {
return tailwindcssMangleCore.cssHandler(content, {
classGenerator: opt.classGenerator,

@@ -15,0 +13,0 @@ runtimeSet,

@@ -1,2 +0,2 @@

import type ClassGenerator from './classGenerator';
import type { ClassGenerator } from 'tailwindcss-mangle-core';
export interface IClassGeneratorContextItem {

@@ -3,0 +3,0 @@ name: string;

@@ -5,12 +5,6 @@ 'use strict';

require('unplugin');
require('./index-2edd594b.js');
require('@babel/types');
require('@babel/core');
require('micromatch');
require('fs');
require('path');
require('parse5');
require('./index-c8e1bdc5.js');
require('postcss');
require('postcss-selector-parser');
require('tailwindcss-mangle-core');
require('tailwindcss-patch');

@@ -17,0 +11,0 @@

@@ -5,12 +5,6 @@ 'use strict';

require('unplugin');
require('./index-2edd594b.js');
require('@babel/types');
require('@babel/core');
require('micromatch');
require('fs');
require('path');
require('parse5');
require('./index-c8e1bdc5.js');
require('postcss');
require('postcss-selector-parser');
require('tailwindcss-mangle-core');
require('tailwindcss-patch');

@@ -17,0 +11,0 @@

{
"name": "unplugin-tailwindcss-mangle",
"version": "0.1.3",
"version": "0.1.4",
"description": "mangle tailwindcss utilities class plugin. support vite and webpack!",

@@ -63,10 +63,5 @@ "main": "./dist/index.js",

"dependencies": {
"@babel/core": "^7.21.5",
"@babel/types": "^7.21.5",
"micromatch": "^4.0.5",
"parse5": "^7.1.2",
"postcss": "^8.4.23",
"postcss-selector-parser": "^6.0.12",
"semver": "^7.5.0",
"unplugin": "^1.3.1",
"tailwindcss-mangle-core": "^1.0.0",
"tailwindcss-patch": "^1.1.1"

@@ -79,13 +74,8 @@ },

"devDependencies": {
"@parse5/tools": "^0.1.0",
"@types/babel__core": "^7.20.0",
"@types/escodegen": "^0.0.7",
"@types/micromatch": "^4.0.2",
"@types/semver": "^7.3.13",
"pkg-types": "^1.0.2",
"simple-functional-loader": "^1.2.1",
"tailwindcss": "^3.3.2",
"tslib": "^2.5.0",
"vite": "^4.3.3",
"webpack": "^5.81.0"
"vite": "^4.3.5",
"webpack": "^5.82.1"
},

@@ -102,5 +92,5 @@ "homepage": "https://github.com/sonofmagic/tailwindcss-mangle",

"build:tsc": "tsc -p tsconfig.json",
"test": "jest",
"_test": "jest",
"_prepare": "tw-patch"
}
}

@@ -108,2 +108,3 @@ # unplugin-tailwindcss-mangle

reserveClassName?: (string | RegExp)[]
// custom generate class name
customGenerate?: (original: string, opts: IClassGeneratorOptions, context: Record<string, any>) => string | undefined

@@ -114,2 +115,3 @@ log?: boolean

ignoreClass?: (string | RegExp)[]
// default 'tw-',for example: tw-a,tw-b, you can set any you want, like '','ice-'
classPrefix?: string

@@ -116,0 +118,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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