Skip to content

Commit

Permalink
Merge pull request #124 from stryju/master
Browse files Browse the repository at this point in the history
added recipe: "Using external config file"
  • Loading branch information
yocontra committed Jan 9, 2014
2 parents 9610d8e + 3d75052 commit 23b2e41
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ See [the FAQ](FAQ.md) for the answers to commonly asked questions.
* [Working with multiple sources in one task](recipes/using-multiple-sources-in-one-task.md)
* [Mocha test runner with gulp](recipes/mocha-test-runner-with-gulp.md)
* [Rebuild only files that change](recipes/rebuild-only-files-that-change.md)
* [Using external config file](recipes/using-external-config-file.md)
* [Introduction to node.js streams](https://github.com/substack/stream-handbook)

## Presentations and slides
Expand Down
49 changes: 49 additions & 0 deletions docs/recipes/using-external-config-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Using external config file
## bonus: keeping those tasks DRY
## bonus2: config.json can be used by another task runner, like `Grunt`

---

`config.json`

```json
{
"desktop" : {
"src" : [
"dev/desktop/js/**/*.js",
"!dev/desktop/js/vendor/**"
],
"dest" : "build/desktop/js"
},
"mobile" : {
"src" : [
"dev/mobile/js/**/*.js",
"!dev/mobile/js/vendor/**"
],
"dest" : "build/mobile/js"
}
}
```

---

`gulpfile.js`

```js
// npm install gulp gulp-uglify
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var config = require('./config.json');

function doStuff(cfg) {
return gulp.src(cfg.src)
.pipe(uglify())
.pipe(gulp.dest(cfg.dest));
}

gulp.task('dry', function () {
doStuff(config.desktop);
doStuff(config.mobile);
});
```

0 comments on commit 23b2e41

Please sign in to comment.