Skip to content

Instantly share code, notes, and snippets.

@sanderhahn
Last active September 11, 2019 14:45
Show Gist options
  • Save sanderhahn/8595191 to your computer and use it in GitHub Desktop.
Save sanderhahn/8595191 to your computer and use it in GitHub Desktop.
Minify and templateCache your Angular Templates using Gulp
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var templates = require('gulp-angular-templatecache');
var minifyHTML = require('gulp-minify-html');
// Minify and templateCache your Angular Templates
// Add a 'templates' module dependency to your app:
// var app = angular.module('appname', [ ... , 'templates']);
gulp.task('templates', function () {
gulp.src([
'./**/*.html',
'!./node_modules/**'
])
.pipe(minifyHTML({
quotes: true
}))
.pipe(templates('templates.js'))
.pipe(gulp.dest('tmp'));
});
// Concat and uglify all your JavaScript
gulp.task('default', ['templates'], function() {
gulp.src([
'./**/*.js',
'!./node_modules/**',
'!./gulpfile.js',
'!./dist/all.js'
])
.pipe(concat('all.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
{
"devDependencies": {
"gulp-angular-templatecache": "~0.3.0",
"gulp-uglify": "~0.1.0",
"gulp-concat": "~2.1.7",
"gulp-ngmin": "~0.1.2",
"gulp-minify-html": "~0.1.0",
"gulp": "~3.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment