Rename CSS Selectors (RCS)
Note: Please make sure your files are not minified/uglified. Do that after processing it with rename-css-selectors
This module renames all CSS selectors in the given files. It will collect all selectors from the given CSS files. Do not worry about your selectors, rcs
will do it for you.
You can also use a config file with the combination of generateMapping and loadMapping, if you already had other projects with the same classes. So all your projects have the same minified selector names - always.
This is a plugin of rcs-core
Contents
Installation
Install with npm or yarn
npm i rename-css-selectors rcs-core
or
yarn add rename-css-selectors rcs-core
Usage
Async:
There are 3 different ways of writing async rcs
code: callbacks, promises and async/await
const rcsCore = require('rcs-core');
const rcs = require('rename-css-selectors')
rcs.config.load();
rcs.mapping.load('./renaming_map.json');
rcsCore.baseLibrary.setExclude(/<%=[\s\S]+%>/);
rcs.process.auto(['**/*.js', '**/*.html', '**/*.css'], options, (err) => {
rcs.mapping.generate('./', { overwrite: true }, (err) => {
});
});
rcs.process.auto(['**/*.js', '**/*.html', '**/*.css'], options)
.then(() => rcs.mapping.generate('./', { overwrite: true }))
.catch(console.error);
(async () => {
try {
await rcs.process.auto(['**/*.js', '**/*.html', '**/*.css'], options);
await rcs.mapping.generate('./', { overwrite: true });
} catch (err) {
console.error(err);
}
})();
Sync:
const rcs = require('rename-css-selectors');
rcs.mapping.load('./renaming_map.json');
try {
rcs.process.autoSync(['**/*.js', '**/*.html', '**/*.css'], options);
rcs.mapping.generateSync('./', { overwrite: true });
} catch (err) {
console.error(err);
}
Methods
Caveats
Correctly using rename-css-selectors
on large project means few rules should be followed.
This document explains most of them.
LICENSE
MIT © Jan Peer Stöcklmair