mangle-css-class-webpack-plugin
Advanced tools
Comparing version 4.0.5 to 4.0.6
@@ -1,5 +0,7 @@ | ||
# Change Log | ||
# Changelog | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
### [4.0.6](https://github.com/sndyuk/mangle-css-class-webpack-plugin/compare/v4.0.5...v4.0.6) (2020-02-20) | ||
<a name="4.0.3"></a> | ||
@@ -6,0 +8,0 @@ ## [4.0.3](https://github.com/sndyuk/mangle-css-class-webpack-plugin/compare/v4.0.2...v4.0.3) (2018-06-13) |
const chalk = require('./chalk'); | ||
const newClassMap = {}; | ||
let newClassSize = 0; | ||
const acceptPrefix = 'abcdefghijklmnopqrstuvwxyz_'.split(''); | ||
const acceptChars = 'abcdefghijklmnopqrstuvwxyz_-0123456789'.split(''); | ||
const generateClassName = (original, opts) => { | ||
const cn = newClassMap[original]; | ||
if (cn) return cn; | ||
function ClassGenerator() { | ||
this.newClassMap = {}; | ||
this.newClassSize = 0; | ||
} | ||
const chars = [] | ||
let rest = (newClassSize - (newClassSize % acceptPrefix.length)) / acceptPrefix.length | ||
if (rest > 0) { | ||
while (true) { | ||
rest -= 1 | ||
const m = rest % acceptChars.length | ||
const c = acceptChars[m] | ||
chars.push(c) | ||
rest -= m | ||
if (rest === 0) { | ||
break | ||
ClassGenerator.prototype = { | ||
generateClassName: function(original, opts) { | ||
const cn = this.newClassMap[original]; | ||
if (cn) return cn; | ||
const chars = [] | ||
let rest = (this.newClassSize - (this.newClassSize % acceptPrefix.length)) / acceptPrefix.length | ||
if (rest > 0) { | ||
while (true) { | ||
rest -= 1 | ||
const m = rest % acceptChars.length | ||
const c = acceptChars[m] | ||
chars.push(c) | ||
rest -= m | ||
if (rest === 0) { | ||
break | ||
} | ||
rest /= acceptChars.length | ||
} | ||
rest /= acceptChars.length | ||
} | ||
} | ||
let prefixIndex = newClassSize % acceptPrefix.length | ||
let prefixIndex = this.newClassSize % acceptPrefix.length | ||
const newClassName = `${acceptPrefix[prefixIndex]}${chars.join('')}` | ||
if (opts.log) { | ||
console.log(`Minify class name from ${chalk.green(original)} to ${chalk.green(newClassName)}`); | ||
const newClassName = `${acceptPrefix[prefixIndex]}${chars.join('')}` | ||
if (opts.log) { | ||
console.log(`Minify class name from ${chalk.green(original)} to ${chalk.green(newClassName)}`); | ||
} | ||
const newClass = { | ||
name: newClassName, | ||
usedBy: [], | ||
}; | ||
this.newClassMap[original] = newClass; | ||
this.newClassSize++; | ||
return newClass; | ||
} | ||
const newClass = { | ||
name: newClassName, | ||
usedBy: [], | ||
}; | ||
newClassMap[original] = newClass; | ||
newClassSize++; | ||
return newClass; | ||
}; | ||
} | ||
module.exports = { | ||
generateClassName: generateClassName | ||
} | ||
module.exports = ClassGenerator |
const { ReplaceSource } = require('webpack-sources'); | ||
const chalk = require('./chalk'); | ||
const classGenerator = require('./classGenerator'); | ||
const ClassGenerator = require('./classGenerator'); | ||
const classGenerator = new ClassGenerator() | ||
const validate = (opts) => { | ||
@@ -6,0 +8,0 @@ if (opts.log) return; |
{ | ||
"name": "mangle-css-class-webpack-plugin", | ||
"version": "4.0.5", | ||
"version": "4.0.6", | ||
"license": "MIT", | ||
@@ -13,10 +13,10 @@ "description": "Minifies and obfuscates the class names in your existing JavaScript, CSS, and HTML without any modern css modules.", | ||
"devDependencies": { | ||
"chalk": "^2.4.1", | ||
"css-loader": "^0.28.11", | ||
"chalk": "^3.0.0", | ||
"css-loader": "^3.4.2", | ||
"html-loader": "^0.5.5", | ||
"jasmine": "^3.1.0", | ||
"rimraf": "^2.6.2", | ||
"standard-version": "^4.4.0", | ||
"style-loader": "^0.21.0", | ||
"webpack": "^4.12.0" | ||
"jasmine": "^3.5.0", | ||
"rimraf": "^3.0.2", | ||
"standard-version": "^7.1.0", | ||
"style-loader": "^1.1.3", | ||
"webpack": "^4.41.6" | ||
}, | ||
@@ -23,0 +23,0 @@ "dependencies": {}, |
8789
129