Skip to content

Instantly share code, notes, and snippets.

@jason-engage
Created September 15, 2015 18:55
Show Gist options
  • Save jason-engage/56b3df8f294af35cd58d to your computer and use it in GitHub Desktop.
Save jason-engage/56b3df8f294af35cd58d to your computer and use it in GitHub Desktop.
Gulp File for Minifying / Concat / Removing Comments and Console logs of Ionic Project
var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var compass = require('gulp-compass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var path = require('path');
var uglify = require('gulp-uglify');
var annotate = require('gulp-ng-annotate');
var sourcemaps = require('gulp-sourcemaps');
var stripDebug = require('gulp-strip-debug');
var minifyHTML = require('gulp-minify-html');
var htmlreplace = require('gulp-html-replace');
var clean = require('gulp-clean');
var paths = {
sass: ['./scss/**/*.scss']
};
gulp.task('default', ['sass']);
gulp.task('sass', function(done) {
var sassOptions = {
project: path.join(__dirname, ''),
css: 'www/css',
sass: 'scss',
};
gulp.src('./scss/ionic.app.scss')
.pipe(compass(sassOptions))
.pipe(gulp.dest('./www/css/'))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({
extname: '.min.css'
}))
.pipe(gulp.dest('./www/css/'))
.on('end', done);
});
gulp.task('watch', function() {
gulp.watch(paths.sass, ['sass']);
});
gulp.task('install', ['git-check'], function() {
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});
gulp.task('git-check', function(done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});
gulp.task('www', function() {
//Minify Template HTML Files
var minifyHtmlOpts = {
empty: true,
quotes: true,
loose: true
};
//Replace Index.html
gulp.src('./www/index.html')
.pipe(htmlreplace({
'css': 'css/styles.min.css',
'js': 'js/bundle.min.js',
'jsremove': ''
}))
.pipe(minifyHTML(minifyHtmlOpts))
.pipe(gulp.dest('./dist'));
//Minify and copy over HTML Templates
gulp.src('./www/templates/*.html')
.pipe(minifyHTML(minifyHtmlOpts))
.pipe(gulp.dest('./dist/templates'));
//Delete ionic.app.css
gulp.src('./www/css/ionic.app.css', {read: false})
.pipe(clean());
//Concat and Minify CSS
gulp.src(['./www/css/*.css'])
.pipe(concat('styles.css'))
//.pipe(sourcemaps.init())
.pipe(minifyCss({
keepSpecialComments: 0
}))
//.pipe(sourcemaps.write('.'))
.pipe(rename('styles.min.css'))
.pipe(gulp.dest('./dist/css'));
//Combine JS Files into core.js
gulp.src('./www/js/*.js')
.pipe(concat('bundle.js'))
.pipe(stripDebug())
.pipe(annotate()) // Makes angular safe to minify.
.pipe(uglify()) // Minifies the concatenated js file.
.pipe(rename('bundle.min.js'))
.pipe(gulp.dest('./dist/js'));
//Copy Over Images Directory
gulp.src(['./www/img/**/*'])
.pipe(gulp.dest('./dist/img'));
//Copy Over Lib Directory
gulp.src(['./www/lib/**/*'])
.pipe(gulp.dest('./dist/lib'));
//Copy Over Fonts Directory
gulp.src(['./www/fonts/**/*'])
.pipe(gulp.dest('./dist/fonts'));
//Copy Over Fonts Directory
gulp.src(['./www/sounds/**/*'])
.pipe(gulp.dest('./dist/sounds'));
});
@jdnichollsc
Copy link

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