All Projects → ctxhou → Postcss Hash Classname

ctxhou / Postcss Hash Classname

Licence: mit
PostCSS plugin to append hash string to your css class name.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Postcss Hash Classname

Sapper Template Firebase
Starter Rollup template for Sapper apps with Firebase functions based on https://github.com/nhristov/sapper-template-rollup.
Stars: ✭ 29 (-49.12%)
Mutual labels:  postcss
Wyhash Rs
wyhash fast portable non-cryptographic hashing algorithm and random number generator in Rust
Stars: ✭ 44 (-22.81%)
Mutual labels:  hash
Postcss At Rules Variables
PostCss plugin to use CSS Custom Properties in at-rule @each, @for, @if, @else and more...
Stars: ✭ 52 (-8.77%)
Mutual labels:  postcss
Jekyll Boilerplate
Helpful files to get started working on a new Jekyll website
Stars: ✭ 30 (-47.37%)
Mutual labels:  postcss
Postjss
Use the power of PostCSS in compiling with JSS
Stars: ✭ 40 (-29.82%)
Mutual labels:  postcss
Smsretrieverapimaster
Automatic SMS Verification with the SMS Retriever API
Stars: ✭ 48 (-15.79%)
Mutual labels:  hash
Hashapi Lib Node
Tierion Hash API client library for Node.js
Stars: ✭ 20 (-64.91%)
Mutual labels:  hash
Merkle Tools
Tools for creating Merkle trees, generating merkle proofs, and verification of merkle proofs.
Stars: ✭ 54 (-5.26%)
Mutual labels:  hash
Sparsepp
A fast, memory efficient hash map for C++
Stars: ✭ 1,021 (+1691.23%)
Mutual labels:  hash
Postcss Selector Not
PostCSS plugin to transform :not() W3C CSS level 4 pseudo class to more compatible CSS (multiple css3 :not() selectors)
Stars: ✭ 49 (-14.04%)
Mutual labels:  postcss
Node Px2rem
Pixel to rem postprocessor
Stars: ✭ 31 (-45.61%)
Mutual labels:  postcss
Postcss Extract Value
PostCSS plugin to extract values from css properties and put them into variables.
Stars: ✭ 39 (-31.58%)
Mutual labels:  postcss
Ckdcss
A tiny set of micro interactions for your checkboxes.
Stars: ✭ 49 (-14.04%)
Mutual labels:  postcss
Ios Category
iOS 工具分类整理
Stars: ✭ 30 (-47.37%)
Mutual labels:  hash
Js Toolbox
CLI tool to simplify the development of JavaScript apps/libraries with little to no configuration. (WORK IN PROGRESS/PACKAGE NOT PUBLISHED).
Stars: ✭ 53 (-7.02%)
Mutual labels:  postcss
Wyhash
A pure-Go wyhash implementation.
Stars: ✭ 21 (-63.16%)
Mutual labels:  hash
Postcss Alias
PostCSS plugin that allows you to create aliases for CSS properties
Stars: ✭ 47 (-17.54%)
Mutual labels:  postcss
React Cool Starter
😎 🐣 A starter boilerplate for a universal web app with the best development experience and a focus on performance and best practices.
Stars: ✭ 1,083 (+1800%)
Mutual labels:  postcss
Hash Bench
Java Hashing, CRC and Checksum Benchmark (JMH)
Stars: ✭ 53 (-7.02%)
Mutual labels:  hash
Postcss Import
PostCSS plugin to inline @import rules content
Stars: ✭ 1,048 (+1738.6%)
Mutual labels:  postcss

postcss-hash-classname

Build Status david download

postcss-hash-classname is a PostCSS plugin to append the hash string to your css class name.

This plugin is inspired by extract-text-webpack-plugin. I really like webpack and extract-text-webpack-plugin used to solve the css scope problem.

But at below cases, we can't require css file directly.

  • you want to do the server-side render with unique css classname
  • your projcet doesn't work with webpack
  • you want to package your projcet to a commonjs/amd/umd library which can't require css file.

If above is your use case, and you still want to keep the unique class name property, this plugin can do the trick!

Example

Input

.foo:not(.bar) {
  ...
}

Output

.foo-7snm3d:not(.bar-8kb5qn) {
  ...
}

then it would generate the corresponding js/json file.

module.exports = {
  "foo": "foo-7snm3d",
  "bar": "bar-8kb5qn"
}

so you can require this js file and set your class name from this object.

When to use?

If you want to build your own library but afraid your class name would conflict user's class name, it's time to use this package.

And if you organize your project in the component way, postcss-hash-classname will generate corresponding js in each folder.

Check out the example folder to know more.

Installation

$ npm install postcss-hash-classname

Usage

gulp example

check the example folder

var opts = {
  hashType: 'md5',
  digestType: 'base32',
  maxLength: 6,
  outputName: 'yoyo',
  dist: './dest',
  type: '.js'
};

var processors = [
  require('postcss-hash-classname')(opts)
];

gulp.task('default', function() {
  return gulp.src('./**.css')
    .pipe(postcss(processors))
    .pipe(gulp.dest('./dest/'));
});

Options

hashType

Hashing algorithm used when hashing classnames and source files' paths.

Default: "md5"

Value: "sha1", "md5", "sha256", "sha512"

digestType

Hash output format.

Default: "base32"

Allowed values: "hex", "base26", "base32", "base36", "base49", "base52", "base58", "base62", "base64"

maxLength

Hash output max length.

Default: 6

Allowed values: maxLength the maximum length in chars (See loader-utils.getHashDigest for reference)

classnameFormat

Used to set the output format of your classname.

Default: [classname]-[hash]

Allowed values:

  • Explicit value: "my-classname"

.A, .b { ... } => .myclassname, .my-classname { ... }

  • Template value: "myclass-[classname]-[hash]"

.A, .b { ... } => .myclass-A-425tvq, .myclass-b-5gbwsr { ... }

Template words supported: "classname", "hash", "classnamehash", "sourcepathash"

  • Callback function (gets passed original classname and source file's path): (classname, sourcePath) => { return path.parse(sourcePath).name + '-' + classname; }

foo.css: .A, .b { ... } => .foo.-A, .foo-b { ... }

bar.css:.A, .b { ... } => .bar-A, .bar-b { ... }

output

Defines output file's path.

Default: none (if not set, will be constructed from options dist, outputName and type)

Allowed values:

  • Explicit value: "./style.js"

./css/style.css => ./style.js

  • Template value: "[dir]/[name]-output.json"

./css/style.css => ./css/style-output.json

Template words supported: "root", "dir", "base", "ext", "name" (See path.parse() for reference)

  • Callback function (gets passed source file's path): (sourcePath) => { return Math.round(1000*Math.random()) + '.js'; }

./css/style.css => ./114.js

dist

Defines output file's target directory. Used only is output option empty.

Default: Same path as source file's

Allowed values:

  • Explicit value: "./processed-styles"

./css/style.css => ./processed-styles/style.js

  • Template value: "[dir]/processed-styles"

./css/style.css => ./css/processed-styles/style.js

Template words supported: "root", "dir", "base", "ext", "name" (See path.parse() for reference)

  • Callback function (gets passed source file's path): (sourcePath) => { return sourcePath + '/processed-styles'; }

./css/style.css => ./css/processed-styles/style.js

outputName

Defines output file's filename. Used only is output option empty.

Default: "style"

Allowed values:

  • Explicit value: "my-style"

./css/style.css => ./my-style.js

  • Template value: "[name]-processed"

./css/style.css => ./style-processed.js

Template words supported: "root", "dir", "base", "ext", "name" (See path.parse() for reference)

  • Callback function (gets passed source file's path): (sourcePath) => { return Math.round(1000*Math.random()); }

./css/style.css => ./984.js

type

Defines output file's extension - ".js" and ".json" supported. Used only is output option empty.

Default: ".js"

Allowed values:

  • Explicit value: ".json"

./css/style.css => ./style.json

  • Template value: "[ext].js"

./css/style.css => ./style.css.js

Template words supported: "root", "dir", "base", "ext", "name" (See path.parse() for reference)

  • Callback function (gets passed source file's path): (sourcePath) => { return Math.round(1000*Math.random()) + '.js'; }

./css/style.css => ./style.984.js

Contributors

License

MIT @ctxhou

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].