All Projects → sndyuk → mangle-css-class-webpack-plugin

sndyuk / mangle-css-class-webpack-plugin

Licence: MIT license
Minifies and obfuscates the class names in your existing JavaScript, CSS, and HTML without any modern css modules.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to mangle-css-class-webpack-plugin

targets-webpack-plugin
Webpack plugin for transcompilig final bundles so they support legacy browsers
Stars: ✭ 15 (-84.37%)
Mutual labels:  webpack-plugin
size-plugin-bot
A Github bot for size-plugin
Stars: ✭ 76 (-20.83%)
Mutual labels:  webpack-plugin
stylelint-bare-webpack-plugin
Stylelint plugin for webpack
Stars: ✭ 15 (-84.37%)
Mutual labels:  webpack-plugin
remove-files-webpack-plugin
A plugin for webpack that removes files and folders before and after compilation.
Stars: ✭ 48 (-50%)
Mutual labels:  webpack-plugin
webpack-stats-diff-plugin
Webpack plugin for reporting changes in bundle sizes across builds
Stars: ✭ 63 (-34.37%)
Mutual labels:  webpack-plugin
prettier-eslint-webpack-plugin
Webpack plugin for prettier-eslint which ESLint's settings is set to JavaScript Standard Style
Stars: ✭ 24 (-75%)
Mutual labels:  webpack-plugin
warnings-to-errors-webpack-plugin
a webpack plugin that can recognize every warning as errors.
Stars: ✭ 17 (-82.29%)
Mutual labels:  webpack-plugin
webpack-shower
🚿 Clean up, Arrange, Filter Webpack Stats
Stars: ✭ 12 (-87.5%)
Mutual labels:  webpack-plugin
monaco-editor-esm-webpack-plugin
No description or website provided.
Stars: ✭ 25 (-73.96%)
Mutual labels:  webpack-plugin
webpack2-externals-plugin
Webpack 2+ fork of Webpack-Externals-Plugin
Stars: ✭ 14 (-85.42%)
Mutual labels:  webpack-plugin
webpack-alioss-upload-plugin
A flexible webpack plugin to upload files to aliyun oss, which supports multiple optional upload methods and parameters.
Stars: ✭ 14 (-85.42%)
Mutual labels:  webpack-plugin
11straps
11straps is a static website boilerplate. It combines Eleventy with Bootstrap 5. 🎉
Stars: ✭ 85 (-11.46%)
Mutual labels:  minifies
image-sprite-webpack-plugin
A webpack plugin that generates spritesheets from your stylesheets.
Stars: ✭ 27 (-71.87%)
Mutual labels:  webpack-plugin
chicio.github.io
👻 Fabrizio Duroni (me 😄) personal website. Created using GatsbyJS, Styled Components, Storybook, Typescript, tsParticles, GitHub pages, Github Actions, Upptime.
Stars: ✭ 20 (-79.17%)
Mutual labels:  webpack-plugin
generate-package-json-webpack-plugin
Generates a package.json file containing the external modules used by your webpack bundle
Stars: ✭ 59 (-38.54%)
Mutual labels:  webpack-plugin
bower-resolve-webpack-plugin
Offers an enhanced bower support for enhanced-resolve plugin.
Stars: ✭ 12 (-87.5%)
Mutual labels:  webpack-plugin
css-chunks-html-webpack-plugin
Injecting css chunks extracted using extract-css-chunks-webpack-plugin to HTML for html-webpack-plugin
Stars: ✭ 22 (-77.08%)
Mutual labels:  webpack-plugin
amp-react-renderer-plugin
⚡Plugin makes it painless to create React component based AMP page⚡
Stars: ✭ 29 (-69.79%)
Mutual labels:  webpack-plugin
flow-webpack-plugin
A webpack plugin allowing to call Flow type checker.
Stars: ✭ 36 (-62.5%)
Mutual labels:  webpack-plugin
2018-package-three-webpack-plugin
[ARCHIVED] Webpack plugin to use Three.js "examples" classes
Stars: ✭ 45 (-53.12%)
Mutual labels:  webpack-plugin

Build Status

mangle-css-class-webpack-plugin

Minifies and obfuscates the class names in JavaScript, CSS, and HTML.

Install

  npm i --save-dev mangle-css-class-webpack-plugin
  yarn add --dev mangle-css-class-webpack-plugin

The latest version WORKS ONLY with Webpack 5. For Webpack v4 & v3 support, install version 4.x([email protected]).

Usage

The plugin will generate optimized class name in HTML, JavaScript, and CSS files. configure as follows:

webpack.config.js

const MangleCssClassPlugin = require('mangle-css-class-webpack-plugin');

module.exports = {
  ...
  plugins: [
    new MangleCssClassPlugin({
      classNameRegExp: '[cl]-[a-z][a-zA-Z0-9_]*',
      log: true,
    }),
  ],
};

This will replace class name matched regex in HTML, JavaScript, CSS files. Identify the class names not to match unexpected words since it replaces all words that are matched with the classNameRegExp. I suggest that your class names have specific prefix or suffix that identified as a class name.

Options

classNameRegExp

e.g. '(abc-|efg-)?[cl]-[a-z][a-zA-Z0-9_]*'
the sample regexp maches l-main, c-textbox, l-main__header, abc-textbox__input, and so on...

If you want to use the back slash \ on the regexp, use [\\\\]* to match class names contained both JS(\\\\) and CSS(\\\\\\\\\\\\\\\\).

reserveClassName

The class names won't be used.
e.g.

reserveClassName: ['fa', 'fas', 'far'],

ignorePrefix

The prefix will be ignored from mangling.
e.g.

classNameRegExp: '(abc-|efg-)?[cl]-[a-z][a-zA-Z0-9_]*',
ignorePrefix: ['abc-', 'efg-'],

In this case, abc-c-textbox__input becomes abc-a.

ignorePrefixRegExp

Same behavior as ignorePrefix.
e.g.

classNameRegExp: '((hover|focus|xs|md|sm|lg|xl)[\\\\]*:)*tw-[a-z_-][a-zA-Z0-9_-]*',
ignorePrefixRegExp: '((hover|focus|xs|md|sm|lg|xl)[\\\\]*:)*',

In this case, hover\:xs\:c-textbox__input becomes hover\:xs\:a.

classGenerator

Override the default class name generator.

// original: original class name
// opts: options of the plugin
// context: own context of the class generator(initial value is just an empty object)
classGenerator: (original, opts, context) => {
  // return custom generated class name.
  // Or return undefined if you want to leave it to the original behavior.
}

Example

Source code

<!-- html -->
<main class='l-abc'>
  <div class='l-efg' />
</main>
// js
document.querySelector('l-efg');
// css
.l-abc {
}
.l-abc .l-efg {
}

Output code

<!-- html -->
<main class='a'>
  <div class='b' />
</main>
// js
document.querySelector('b');
// css
.a {
}
.a .b {
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].