UNPKG

gulp-io

Version:

iio's front-end build tools.

67 lines (59 loc) 2.42 kB
/* # Precompiling Angular templates Angular template files are generally cached by the browser, which makes them not update if we change them. The ng-template plugin precompiles them to a javascript structure, which is then cached by Angular's `templateCache`, so that they don't get hidden by the browser cache. As an added bonus, they are all compiled to one single file, so they all fit in one request. */ module.exports = function(gulp) { // DEPENDENCIES var minifyHtml = require('gulp-minify-html'), ngTemplate = require('gulp-ng-template'); // INCLUDE DEVELOPMENT DEPENDENCIES try { var reload = require('browser-sync').reload; } catch (err) { gulp.gutil.log("Ignoring '" + gulp.gutil.colors.red('browser-sync') + "'. File not found."); } try { var sourcemaps = require('gulp-sourcemaps'); } catch (err) { gulp.gutil.log("Ignoring '" + gulp.gutil.colors.red('gulp-sourcemaps') + "'. File not found."); } // CONFIGURATIONS var config = gulp.config.templates; // TASKS // ANGULAR TEMPLATE -> PRODUCTION gulp.task('templates:angular:prod', config.dependencies, function() { gulp.src(gulp.path.join(gulp.config.webapp, config.src, config.type)) .pipe(gulp.plumber()) .pipe(minifyHtml({ empty: true, quotes: true })) .pipe(ngTemplate({ moduleName: config.moduleName, standalone: true, filePath: gulp.path.join(gulp.config.webapp, config.dest, config.output) })); }); // ANGULAR TEMPLATE -> DEVELOPMENT gulp.task('templates:angular:dev', config.dependencies, function() { gulp.src(gulp.path.join(gulp.config.webapp, config.src, config.type)) .pipe(gulp.plumber()) .pipe(ngTemplate({ moduleName: config.moduleName, standalone: true, filePath: gulp.path.join(gulp.config.webapp, config.dest, config.output) })) .pipe(reload({ stream: true })); }); // ANGULAR TEMPLATE -> WATCH, INJECT OR RELOAD gulp.task('templates:angular:dev:watch', ['templates:angular:dev'], function() { this.watch(gulp.path.join(gulp.config.webapp, config.src, config.type), ['templates:angular:dev']); }); return gulp; };