0.1.3 • Published 6 years ago

stylus-plugin-minify-words v0.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

stylus-plugin-minify-words

Build Status Build status codecov dependencies Status devDependencies Status

A Stylus plugin to shorten words.

Install

npm install stylus-plugin-minify-words --save-dev

Usage

1. Use public(), private() and require() in your stylus-sheet

// button.styl
.{private('ok')}
	color green

// style.styl
@require './button'
.{public('header')}
	font-size 14px
	&>.{require('./button.styl', 'ok')}
		color blue

2. Compile stylus-sheet with this plugin

const fs = require('fs');
const {WordMinifier} = require('stylus-plugin-minify-words');
const minifier = new WordMinifier();
stylus(fs.readFileSync('main.styl', 'utf8'))
.use(minifier.plugin())
.render((error, css) => {
  console.log(css);
  console.log(minifier);
});

You'll get css below.

._0 {
  color: green;
}
._1 {
  font-size: 14px;
}
._1>._0 {
  color: blue;
}

And the minifier has the result.

Map {
  '/path/to/button.styl' => Map {
    'ok' => {minified: '_0', public: true}
  },
  '/path/to/style.styl' => Map {
    'header' => {minified: '_1', public: true}
  }
}

Javascript API

WordMinifier

A WordMinifier is a Map.<file, words>.

  • file: String. The absolute path to the file
  • words: Words.

WordMinifier.prototype.plugin()

returns a function passed to .use().

Words

A Words is a Map.<word, {minified, public}>.

  • word: String. The original word.
  • minified: String. The minified word.
  • public: Boolean. If true, the word is declared by public() at least once.

License

MIT

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

7 years ago

0.0.1

7 years ago