New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

minify-selectors

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minify-selectors

Post-processor that minifies classes and IDs in CSS, HTML and Javascript files.

  • 0.11.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

minify-selectors

Post-processor that minifies classes and IDs selector names in CSS, HTML and Javascript files. Each unique selector, and any subsequent occurances elsewhere, is converted into an ultracompact name.

Wrings out that little bit more out of your payload sizes and shave off a wee bit off file parse times. Additionally adds a certain degree of obfuscation to your selector names and stylesheets.


Examples

CSS

Source:

[id='page--default'] { … }                               ‎
.sidebar, .site-nav { … }
.sidebar .search:focus-within { … }
.sidebar--expanded a.is-active { … }

Output:

[id='a'], { … }                                          ‎
.b, .c { … }
.b .d:focus-within { … }
.e a.f { … }

HTML

Source:

<body id="page--default">
  <nav class="site-nav">
    <div class="search has-content">
      <label for="site-search" class="text--muted text--c
        enter">
        Search app
      </label>
      <input type="text" id="site-search" class="form-inp
        ut--single form-input--lg border--thick">
    </div>
  </nav>
</body>

Output:

<body id="a">                                            ‎
  <nav class="c">
    <div class="d a1">
      <label for="y" class="F j">
        Search app
      </label>
      <input type="text" id="y" class="A9 t Av">
    </div>
  </nav>
</body>

JS

Source:

for (let link of document.querySelectorAll('a.anchor')) {‎
  link.classList.remove('is-active');
}

Output:

for (let link of document.querySelectorAll('a.Bd')) {    ‎
  link.classList.remove('f');
}

For a full outline of capabilities and current limitations, see parse_selectors/info.md.


Usage

Please note: minify-selectors only supports regular CSS, HTML and JS files. minify-selectors should be one of the final steps in your build process — SASS/SCSS, LESS, Typescript, JQuery, Handlebars, etc. should be compiled or transpiled first into its respective vanilla form.

CLI

  1. Install from npm:

    npm i -g minify-selectors
    
  2. Run in command line:

    minify-selectors --input "example/dir/src" --output "example/dir/dist"
    

npm scripts

  1. Install from npm:

    npm i minify-selectors
    
  2. Include minify-selectors in your package.json scripts:

    "scripts": {
      "build": "npm run build:webpack && npm run build:minify-selectors",
      "build:minify-selectors": "minify-selectors --input \"example/dir/src/\" --output \"example/dir/dist/\"",
      "build:webpack": "webpack --config config/webpack-prod.config.js"
    },
    
  3. Run npm script:

    npm run build
    

Options

FlagDescription
--input (or -i) Directory or file to process. If a directory path is provided — any CSS, HTML and JS files in the given directory and sub-directories will be parsed. If only a filepath is provided — only the given file will be parsed.
--output (or -o) Directory to ouput processed files to. Setting the output path to be the same as the input path will overwrite existing files.
--alphabet Custom sequence of characters to use when encoding.

By default, selector names will be encoded using the following base 62 string: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
--start-index Index to start incrementing and encoding from.

By default, this will begin from `0` (essentially `a` if using the default alphabet).

Keywords

FAQs

Package last updated on 25 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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