Created
February 2, 2016 17:47
-
-
Save miguelerm/dd1562512940c633511e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// just a demo gulpfile for my projects | |
require('es6-promise').polyfill(); | |
var del = require('del'), | |
gulp = require('gulp'), | |
iife = require('gulp-iife'), | |
sass = require('gulp-sass'), | |
gulpif = require('gulp-if'), | |
hash = require('gulp-hash-src'), | |
useref = require('gulp-useref'), | |
uglify = require('gulp-uglify'), | |
inject = require('gulp-inject'), | |
annotate = require('gulp-ng-annotate'), | |
cssnano = require('gulp-cssnano'), | |
htmlmin = require('gulp-htmlmin'), | |
ngtemplate = require('gulp-angular-templatecache'); | |
var wwwroot = './wwwroot'; | |
var tmp = '../../tmp'; | |
var distPath = '../../artifacts/dist' | |
gulp.task('publish', ['prevent-browser-cache']) | |
gulp.task('prevent-browser-cache', ['compile-html'], function () { | |
return gulp.src([distPath + "/index.html", distPath + '/**/*.css']) | |
.pipe(hash({ build_dir: distPath, src_path: distPath })) | |
.pipe(gulp.dest(distPath)); | |
}); | |
gulp.task('compile-html', ['copy-folders', 'compile-ng-templates-into-js', 'compile-sass-into-css'], function () { | |
return gulp.src(wwwroot + '/index.html') | |
.pipe(inject(gulp.src([tmp + '/templates.js'], { read: false }), { relative: true })) | |
.pipe(useref()) | |
.pipe(gulpif('*/app.js', iife())) | |
.pipe(gulpif('*/app.js', annotate())) | |
.pipe(gulpif('*.js', uglify())) | |
.pipe(gulpif('*.css', cssnano())) | |
.pipe(gulpif('*.html', htmlmin({ collapseWhitespace: true, removeComments: true }))) | |
.pipe(gulp.dest(distPath)); | |
}); | |
gulp.task('compile-sass-into-css', function () { | |
return gulp.src(wwwroot + '/sass/main.scss') | |
.pipe(sass().on('error', sass.logError)) | |
.pipe(gulp.dest(wwwroot + '/sass')); | |
}); | |
gulp.task('compile-ng-templates-into-js', function () { | |
return gulp.src(wwwroot + '/views/**/*.html') | |
.pipe(htmlmin({ collapseWhitespace: true, removeComments: true })) | |
.pipe(ngtemplate({ root: 'views/', module: 'minovateApp' })) | |
.pipe(gulp.dest(tmp)); | |
}); | |
gulp.task('copy-folders', ['clean'], function () { | |
return gulp.src([ | |
wwwroot + "/fonts/**/*", | |
wwwroot + "/images/**/*", | |
wwwroot + "/languages/**/*", | |
wwwroot + "/styles/images/**/*", | |
wwwroot + "/*.*", | |
'!' + wwwroot + '/web.config' | |
], { base: wwwroot }).pipe(gulp.dest(distPath)); | |
}); | |
gulp.task('clean', function () { | |
return del([distPath + '/**/*', tmp + '/**/*', '!' + distPath + '/web.config'], { force: true }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment