Skip to content

Instantly share code, notes, and snippets.

@kimjoar
Last active December 31, 2015 21:29
Show Gist options
  • Save kimjoar/8046855 to your computer and use it in GitHub Desktop.
Save kimjoar/8046855 to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var concat = require('gulp-concat');
var header = require('gulp-header');
var footer = require('gulp-footer');
var templateCache = require('./template-cache');
var templateCacheWrapper = require('./template-cache-wrapper');
gulp.task('default', function() {
var templateHeader = "{{ angular }}.module('{{ module }}'{{ standalone }}).run(['$templateCache', function($templateCache) {\n";
var templateFooter = "}]);\n"
gulp.src('./templates/*.html')
// this is my gulp plugin, but it won't work without a header and footer in the concat'ed file
.pipe(templateCache())
.pipe(concat("template.js"))
.pipe(header(templateHeader, {
angular: 'angular',
module: 'app',
standalone: ', []'
}))
.pipe(footer(templateFooter))
.pipe(gulp.dest('./dist/'))
});
// for ease of use, I want to create a wrapper
gulp.task('default', function() {
gulp.src('./templates/*.html')
.pipe(templateCacheWrapper())
.pipe(gulp.dest('./dist/'))
});
@kimjoar
Copy link
Author

kimjoar commented Dec 19, 2013

(yeah, as you probably can tell, I'm not used to working with streams yet)

@yocontra
Copy link

The stream you return from your plugin function can be piped to other streams.

Swap

return yourPluginStream

for

return yourPluginStream.pipe(header()).pipe(footer())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment