Skip to content

Commit 97a64d3

Browse files
committed
added recipe for external config file
1 parent 099a8eb commit 97a64d3

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

docs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See [the FAQ](FAQ.md) for the answers to commonly asked questions.
1313
* [Working with multiple sources in one task](recipes/using-multiple-sources-in-one-task.md)
1414
* [Mocha test runner with gulp](recipes/mocha-test-runner-with-gulp.md)
1515
* [Rebuild only files that change](recipes/rebuild-only-files-that-change.md)
16+
* [Using external config file](recipes/using-external-config-file.md)
1617
* [Introduction to node.js streams](https://github.com/substack/stream-handbook)
1718

1819
## Presentations and slides
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Using external config file
2+
## bonus: keeping those tasks DRY
3+
## bonus2: config.json can be used by another task runner, like `Grunt`
4+
5+
---
6+
7+
`config.json`
8+
9+
```json
10+
{
11+
"desktop" : {
12+
"src" : [
13+
"dev/desktop/js/**/*.js",
14+
"!dev/desktop/js/vendor/**"
15+
],
16+
"dest" : "build/desktop/js"
17+
},
18+
"mobile" : {
19+
"src" : [
20+
"dev/mobile/js/**/*.js",
21+
"!dev/mobile/js/vendor/**"
22+
],
23+
"dest" : "build/mobile/js"
24+
}
25+
}
26+
```
27+
28+
---
29+
30+
`gulpfile.js`
31+
32+
```js
33+
// npm install gulp gulp-uglify
34+
var gulp = require('gulp');
35+
var uglify = require('gulp-uglify');
36+
var config = require('./config.json');
37+
38+
function doStuff(cfg) {
39+
return gulp.src(cfg.src)
40+
.pipe(uglify())
41+
.pipe(gulp.dest(cfg.dest));
42+
}
43+
44+
gulp.task('dry', function () {
45+
doStuff(config.desktop);
46+
doStuff(config.mobile);
47+
});
48+
```
49+

0 commit comments

Comments
 (0)