forked from DamonOehlman/stylify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (36 loc) · 1.15 KB
/
index.js
File metadata and controls
52 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* jshint node: true */
'use strict';
/**
# stylify
browserify v2 plugin for [stylus](https://github.com/LearnBoost/stylus).
## Example Usage
Usage is very simple when combined with the
[insert-css](https://github.com/substack/insert-css) (or similar) module.
Consider the following example, which dynamically creates a couple of
div tags, and dynamically assigned styles:
<<< examples/simple.js
You can see the final statement uses a familar node `require` call to
bring in a stylus stylesheet:
<<<css examples/simple.styl
**/
var stylus = require('stylus');
var nib = require('nib');
var cleanCss = require('clean-css');
var through = require('through');
function compile(file, data) {
var compiled = stylus(data, { filename: file }).use(nib()).render();
var minified = (new cleanCss).minify(compiled);
return 'module.exports = ' + JSON.stringify(minified) + ';';
}
module.exports = function (file) {
var data = '';
function write (buf) {
data += buf;
}
function end () {
this.queue(compile(file, data));
this.queue(null);
}
if (!/\.styl$/.test(file)) return through();
return through(write, end);
};