UNPKG

3.29 kBMarkdownView Raw
1# gulp-stylus
2[![Build Status](https://travis-ci.org/stevelacy/gulp-stylus.png?branch=master)](https://travis-ci.org/stevelacy/gulp-stylus)
3[![NPM version](https://badge.fury.io/js/gulp-stylus.png)](http://badge.fury.io/js/gulp-stylus)
4
5> Compile [Stylus](http://learnboost.github.io/stylus/) with gulp (gulpjs.com)
6
7## Information
8
9<table>
10<tr>
11<td>Package</td><td>gulp-stylus</td>
12</tr>
13<tr>
14<td>Description</td>
15<td>Stylus plugin for gulp</td>
16</tr>
17<tr>
18<td>Node Version</td>
19<td>>= 0.9</td>
20</tr>
21<tr>
22<td>Gulp Version</td>
23<td>>= 3.x</td>
24</tr>
25</table>
26
27## Usage
28
29#### Install
30
31```sh
32$ npm install --save-dev gulp-stylus
33```
34
35## Examples
36
37```javascript
38
39// include the required packages.
40var gulp = require('gulp');
41var data = require('gulp-data');
42var stylus = require('gulp-stylus');
43
44
45// include, if you want to work with sourcemaps
46var sourcemaps = require('gulp-sourcemaps');
47
48// Get one .styl file and render
49gulp.task('one', function () {
50 return gulp.src('./css/one.styl')
51 .pipe(stylus())
52 .pipe(gulp.dest('./css/build'));
53});
54
55// Options
56// Options compress
57gulp.task('compress', function () {
58 return gulp.src('./css/compressed.styl')
59 .pipe(stylus({
60 compress: true
61 }))
62 .pipe(gulp.dest('./css/build'));
63});
64
65
66// Set linenos
67gulp.task('linenos', function () {
68 return gulp.src('./css/linenos.styl')
69 .pipe(stylus({linenos: true}))
70 .pipe(gulp.dest('./css/build'));
71});
72
73// Include css
74// Stylus has an awkward and perplexing 'include css' option
75gulp.task('include-css', function() {
76 return gulp.src('./css/*.styl')
77 .pipe(stylus({
78 'include css': true
79 }))
80 .pipe(gulp.dest('./'));
81
82});
83
84// Inline sourcemaps
85gulp.task('sourcemaps-inline', function () {
86 return gulp.src('./css/sourcemaps-inline.styl')
87 .pipe(sourcemaps.init())
88 .pipe(stylus())
89 .pipe(sourcemaps.write())
90 .pipe(gulp.dest('./css/build'));
91});
92
93// External sourcemaps
94gulp.task('sourcemaps-external', function () {
95 return gulp.src('./css/sourcemaps-external.styl')
96 .pipe(sourcemaps.init())
97 .pipe(stylus())
98 .pipe(sourcemaps.write('.'))
99 .pipe(gulp.dest('./css/build'));
100});
101
102// Pass an object in raw form to be accessable in stylus
103var data = {red: '#ff0000'};
104gulp.task('pass-object', function () {
105 gulp.src('./sty/main.styl')
106 .pipe(stylus({ rawDefine: { data: data }}))
107 .pipe(gulp.dest('./css/build'));
108});
109
110// Use with gulp-data
111gulp.task('gulp-data', function() {
112 gulp.src('./components/**/*.styl')
113 .pipe(data(function(file){
114 return {
115 componentPath: '/' + (file.path.replace(file.base, '').replace(/\/[^\/]*$/, ''))
116 };
117 }))
118 .pipe(stylus())
119 .pipe(gulp.dest('./css/build'));
120});
121
122/* Ex:
123body
124 color: data.red;
125*/
126
127// Default gulp task to run
128gulp.task('default', ['one', 'compress', 'linenos', 'sourcemaps-inline', 'sourcemaps-external', 'pass-object']);
129
130```
131
132##### You can view more examples in the [example folder.](https://github.com/stevelacy/gulp-stylus/tree/master/examples)
133
134## Extras
135You can access the original `stylus` module that `gulp-stylus` uses.
136```
137var originalStylus = require('gulp-stylus').stylus;
138```
139
140## Options
141#### All stylus options are passed to [accord/stylus](https://github.com/jenius/accord/blob/master/docs/stylus.md)
142
143
144
145## LICENSE [MIT](LICENSE)