Skip to content

Commit f58bce6

Browse files
Stephen SmithStephen Smith
authored andcommitted
Added sass scripting capability
1 parent 8a68f4f commit f58bce6

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This package provides common gulp tasks for building react components with:
66
* Browserify for transforming JSX and creating distribution builds
77
* Watchify for automatic, efficient rebundling on file changes
88
* Connect for serving examples during development, with live-reload integration
9-
* LESS stylesheets for examples
9+
* LESS/Sass stylesheets for examples
1010
* Publishing examples to Github Pages
1111
* Publishing packages to npm and bower
1212

@@ -23,7 +23,7 @@ The tasks assume you are following the following conventions for your project:
2323
* A standalone package will be published to a dist folder (for Bower)
2424
* Examples consist of
2525
* Static file(s) (e.g. html, images, etc)
26-
* One or more stylesheets to be generated with LESS
26+
* One or more stylesheets to be generated with LESS/Sass
2727
* One or more scripts to be bundled with Browserify
2828
* Examples will be packaged into an examples dist folder, and published to github pages
2929

@@ -143,6 +143,36 @@ initGulpTasks(gulp, taskConfig);
143143

144144
```
145145

146+
#### Sass instead of Less
147+
148+
If your project uses Sass instead of Less, use the same syntax but with `sass` instead of `less`.
149+
150+
```javascript
151+
var taskConfig = {
152+
153+
component: {
154+
name: 'MyComponent',
155+
dependencies: [ /* ... */ ],
156+
sass: {
157+
path: 'sass',
158+
entry: 'my-component.scss'
159+
}
160+
},
161+
162+
example: {
163+
src: 'example/src',
164+
dist: 'example/dist',
165+
files: [ /* ... */ ],
166+
scripts: [ /* ... */ ],
167+
sass: [
168+
'app.scss'
169+
]
170+
}
171+
172+
};
173+
174+
```
175+
146176
## Contributing
147177

148178
I wrote this package because maintaining my build process across multiple packages became a repetitive chore with large margin for error.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"gulp-less": "^3.0.3",
3131
"gulp-minify-css": "^1.2.1",
3232
"gulp-rename": "^1.2.2",
33+
"gulp-sass": "^2.3.1",
3334
"gulp-streamify": "^1.0.2",
3435
"gulp-uglify": "^1.4.1",
3536
"gulp-util": "^3.0.6",

tasks/dist.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var browserify = require('browserify');
33
var del = require('del');
44
var gutil = require('gulp-util');
55
var less = require('gulp-less');
6+
var sass = require('gulp-sass');
67
var rename = require('gulp-rename');
78
var shim = require('browserify-shim');
89
var source = require('vinyl-source-stream');
@@ -52,6 +53,17 @@ module.exports = function (gulp, config) {
5253
.pipe(gulp.dest('dist'))
5354
});
5455
buildTasks.push('build:dist:css');
56+
} else if (config.component.sass && config.component.sass.entry) {
57+
gulp.task('build:dist:css', ['clean:dist'], function () {
58+
return gulp.src(config.component.sass.path + '/' + config.component.sass.entry)
59+
.pipe(sass())
60+
.pipe(rename(config.component.pkgName + '.css'))
61+
.pipe(gulp.dest('dist'))
62+
.pipe(rename(config.component.pkgName + '.min.css'))
63+
.pipe(minifyCSS())
64+
.pipe(gulp.dest('dist'))
65+
});
66+
buildTasks.push('build:dist:css');
5567
}
5668

5769
gulp.task('build:dist', buildTasks);

tasks/examples.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var connect = require('gulp-connect');
66
var del = require('del');
77
var gutil = require('gulp-util');
88
var less = require('gulp-less');
9+
var sass = require('gulp-sass');
910
var merge = require('merge-stream');
1011
var shim = require('browserify-shim');
1112
var source = require('vinyl-source-stream');
@@ -127,10 +128,20 @@ module.exports = function (gulp, config) {
127128
});
128129

129130
gulp.task('build:example:css', function () {
130-
if (!config.example.less) return;
131+
var css = null;
132+
var cssInterpreter = function() {};
133+
if (config.example.less) {
134+
css = config.example.less;
135+
cssInterpreter = less;
136+
} else if (config.example.sass) {
137+
css = config.example.sass;
138+
cssInterpreter = sass;
139+
} else {
140+
return;
141+
}
131142

132-
return gulp.src(config.example.src + '/' + config.example.less)
133-
.pipe(less())
143+
return gulp.src(config.example.src + '/' + css)
144+
.pipe(cssInterpreter())
134145
.pipe(gulp.dest(config.example.dist))
135146
.pipe(connect.reload());
136147
});
@@ -150,15 +161,19 @@ module.exports = function (gulp, config) {
150161
return config.example.src + '/' + i;
151162
}), ['build:example:files']);
152163

153-
var watchLESS = [];
164+
var watchCSS = [];
154165
if (config.example.less) {
155-
watchLESS.push(config.example.src + '/' + config.example.less);
166+
watchCSS.push(config.example.src + '/' + config.example.less);
167+
} else if (config.example.sass) {
168+
watchCSS.push(config.example.src + '/' + config.example.sass);
156169
}
157170

158171
if (config.component.less && config.component.less.path) {
159-
watchLESS.push(config.component.less.path + '/**/*.less');
172+
watchCSS.push(config.component.less.path + '/**/*.less');
173+
} else if (config.component.sass && config.component.sass.path) {
174+
watchCSS.push(config.component.sass.path + '/**/*.scss');
160175
}
161176

162-
gulp.watch(watchLESS, ['build:example:css']);
177+
gulp.watch(watchCSS, ['build:example:css']);
163178
});
164179
};

0 commit comments

Comments
 (0)