Comments (4)
Sorry for the late response. Could you share a minimal example of your files?
from node-rename-css-selectors.
I'm not doing anything special. I'm pretty sure that the below doesn't really add any new information to what I've already reported, but here's a very clear example.
Create a folder with a subfolder called 'outdir'.
Create a javascript file called auto-rename-css-classes.mjs
import rcsCore from 'rcs-core';
import rcs from 'rename-css-selectors';
(async function autoRenameCssClasses() {
const rcsOptions = {
overwrite: false, // we do not want to overwrite the html file.
// cwd: 'class-renaming-demo',
newPath: 'outdir',
// optimize: true //It's supposed to be on by default.
};
try {
await rcs.process.auto(
['incorrectly-minified-class-names-demo.html'],
rcsOptions
);
await rcs.mapping.generate('./', {
overwrite: true, // We want to always overwrite the mapping file.
origValues: false,
fileName: 'renaming-map-min',
});
} catch (err) {
console.log('error in rcs', err);
}
})();
Create a file called incorrectly-minified-class-names-demo.html
<!DOCTYPE html>
<html>
<style>
.unused-class-1,
.unused-class-2,
.unused-class-3,
.unused-class-4,
.unused-class-5,
.unused-class-6,
.unused-class-7,
.unused-class-8,
.unused-class-9,
.unused-class-10,
.unused-class-11,
.unused-class-12,
.unused-class-13,
.unused-class-14,
.unused-class-15,
.unused-class-16,
.unused-class-17,
.unused-class-18,
.unused-class-19,
.unused-class-20,
.unused-class-21,
.unused-class-22,
.unused-class-23,
.unused-class-24,
.unused-class-25,
.unused-class-26,
.unused-class-27,
.unused-class-28,
.unused-class-29,
.unused-class-30 {
color: red;
}
.in-use-class1,
.most-frequent-class,
.in-use-class3 {
color: blue;
}
</style>
<body>
<span class="in-use-class1"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="most-frequent-class"></span>
<span class="in-use-class3"></span>
</body>
</html>
In the folder run node auto-rename-css-classes.mjs
.
This produces the following renaming-map-min.json
:
{
"selectors": {
".t": "unused-class-1",
".n": "unused-class-2",
".r": "unused-class-3",
".i": "unused-class-4",
".s": "unused-class-5",
".o": "unused-class-6",
".u": "unused-class-7",
".a": "unused-class-8",
".f": "unused-class-9",
".l": "unused-class-10",
".c": "unused-class-11",
".h": "unused-class-12",
".p": "unused-class-13",
".d": "unused-class-14",
".v": "unused-class-15",
".m": "unused-class-16",
".g": "unused-class-17",
".y": "unused-class-18",
".b": "unused-class-19",
".w": "unused-class-20",
".x": "unused-class-21",
".k": "unused-class-22",
"._": "unused-class-23",
".j": "unused-class-24",
".q": "unused-class-25",
".z": "unused-class-26",
".te": "unused-class-27",
".tt": "unused-class-28",
".tn": "unused-class-29",
".tr": "unused-class-30",
".ti": "in-use-class1",
".ts": "most-frequent-class",
".to": "in-use-class3"
}
}
Notice that:
- all single letter class names are taken by unused classes
- the most frequent class is listed between two other classes only used once and thus may not have been given a single letter even if it wasn't for the unused classes.
from node-rename-css-selectors.
To be clear for any other observers here:
- the optimisation functionality I am expecting relates to the "completed" issue #80 .
I am indeed using the version rename-css-selectors": "^4.1.0
from node-rename-css-selectors.
Side note: the class "e" is never used. This is first letter of alphabet at https://github.com/JPeer264/node-rcs-core/blob/7d6fb24e3182484887626eb358e1ab87a99d5afd/lib/nameGenerator.ts#L17
I guess an off-by-one bug?
from node-rename-css-selectors.
Related Issues (20)
- 3.2.4 breaks calc with css variables HOT 2
- Messes up with the `~` character HOT 4
- Uncaught TypeError: (0 , r.default)(...).at is not a function HOT 4
- Ignore specific class HOT 1
- renaming html tags such as div HOT 3
- [BUG] It renames EJS HOT 7
- Add documentation for rcsCore usage in rename-css-selectors
- mismatched layout after running rcs HOT 3
- Integration with Gulp HOT 16
- Ids and classes are treated as the same identity HOT 10
- Not completely renamed if there's a line break between class names HOT 6
- Exclude classes with special characters HOT 6
- [Q] Webpack Usage? HOT 6
- Does this plugin optimize the library so most frequent classes get one letter not two? HOT 2
- Minify as a function HOT 2
- Bug: Textarea and other common words replaced HOT 3
- getElementById string being replaced by class selector name instead of id
- Unchanging custom class name HOT 1
- Is it possible to use rcs-core with vite/rollup)?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-rename-css-selectors.