1 | # gulp-stylus
|
2 | [](https://travis-ci.org/stevelacy/gulp-stylus)
|
3 | [](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.
|
40 | var gulp = require('gulp');
|
41 | var data = require('gulp-data');
|
42 | var stylus = require('gulp-stylus');
|
43 |
|
44 |
|
45 | // include, if you want to work with sourcemaps
|
46 | var sourcemaps = require('gulp-sourcemaps');
|
47 |
|
48 | // Get one .styl file and render
|
49 | gulp.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
|
57 | gulp.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
|
67 | gulp.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
|
75 | gulp.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
|
85 | gulp.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
|
94 | gulp.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
|
103 | var data = {red: '#ff0000'};
|
104 | gulp.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
|
111 | gulp.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:
|
123 | body
|
124 | color: data.red;
|
125 | */
|
126 |
|
127 | // Default gulp task to run
|
128 | gulp.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
|
135 | You can access the original `stylus` module that `gulp-stylus` uses.
|
136 | ```
|
137 | var 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)
|