Created
November 17, 2015 11:58
-
-
Save Insayt/7e76390854d3b90351cb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
var _ = require('lodash'), | |
gulp = require('gulp'), | |
watch = require('gulp-watch'), | |
plumber = require('gulp-plumber'), | |
prefixer = require('gulp-autoprefixer'), | |
uglify = require('gulp-uglify'), | |
less = require('gulp-less'), | |
stripCssComments = require('gulp-strip-css-comments'), | |
sourcemaps = require('gulp-sourcemaps'), | |
rigger = require('gulp-rigger'), | |
cssmin = require('gulp-minify-css'), | |
imagemin = require('gulp-imagemin'), | |
pngquant = require('imagemin-pngquant'), | |
del = require('del'), | |
concat = require('gulp-concat'), | |
ngAnnotate = require('gulp-ng-annotate'), | |
templateCache = require('gulp-angular-templatecache'); | |
var path = { | |
build: { | |
html: 'frontend/web/', | |
template: 'frontend/web/ng-template/', | |
js: 'frontend/web/js/', | |
css: 'frontend/web/css/', | |
img: 'frontend/web/images/', | |
fonts: 'frontend/web/fonts/', | |
flash: 'frontend/web/flash/', | |
language: 'frontend/web/language' | |
}, | |
src: { | |
html: 'frontend/static/*.html', | |
template: 'frontend/static/ng-template/**/*.html', | |
js: 'frontend/static/js/application.js', | |
style: 'frontend/static/style/application.less', | |
img: 'frontend/static/images/**/*.*', | |
fonts: 'frontend/static/fonts/**/*.*', | |
flash: 'frontend/static/flash/*.swf', | |
language: 'frontend/static/language/*.js' | |
}, | |
watch: { | |
html: 'frontend/static/**/*.html', | |
js: 'frontend/static/js/**/*.js', | |
style: 'frontend/static/style/**/*.less', | |
img: 'frontend/static/images/**/*.*', | |
fonts: 'frontend/static/fonts/**/*.*', | |
language: 'frontend/static/language/*.js' | |
}, | |
clean: { | |
template: 'frontend/web/ng-template/', | |
js: 'frontend/web/js/', | |
css: 'frontend/web/css/', | |
img: 'frontend/web/images/', | |
fonts: 'frontend/web/fonts/', | |
flash: 'frontend/web/flash/', | |
language: 'frontend/web/language/' | |
} | |
}; | |
gulp.task('clean', function () { | |
console.log(_.values(path.clean)); | |
return del.sync(_.values(path.clean)); | |
}); | |
gulp.task('html:build', function () { | |
gulp.src(path.src.html) | |
.pipe(plumber()) | |
.pipe(rigger()) | |
.pipe(gulp.dest(path.build.html)); | |
gulp.src(path.src.template) | |
.pipe(plumber()) | |
.pipe(rigger()) | |
.pipe(templateCache({ module:'templates', standalone:true })) | |
.pipe(gulp.dest(path.clean.js)); | |
}); | |
gulp.task('js:build', function () { | |
gulp.src(path.src.js) | |
.pipe(plumber()) | |
.pipe(rigger()) | |
.pipe(ngAnnotate()) | |
.pipe(sourcemaps.init()) | |
.pipe(uglify()) | |
.pipe(sourcemaps.write()) | |
.pipe(gulp.dest(path.build.js)); | |
}); | |
gulp.task('style:build', function () { | |
gulp.src(path.src.style) | |
.pipe(plumber()) | |
.pipe(sourcemaps.init()) | |
.pipe(less()) | |
.pipe(prefixer()) | |
.pipe(stripCssComments({ | |
preserve: false | |
})) | |
.pipe(cssmin()) | |
.pipe(sourcemaps.write()) | |
.pipe(gulp.dest(path.build.css)); | |
}); | |
gulp.task('image:build', function () { | |
gulp.src(path.src.img) | |
.pipe(plumber()) | |
.pipe(imagemin({ | |
progressive: true, | |
svgoPlugins: [{removeViewBox: false}], | |
use: [pngquant()], | |
interlaced: true | |
})) | |
.pipe(gulp.dest(path.build.img)); | |
}); | |
gulp.task('fonts:build', function() { | |
gulp.src(path.src.fonts) | |
.pipe(gulp.dest(path.build.fonts)) | |
}); | |
gulp.task('flash:build', function() { | |
gulp.src(path.src.flash) | |
.pipe(gulp.dest(path.build.flash)) | |
}); | |
gulp.task('language', function() { | |
gulp.src(path.src.language) | |
.pipe(plumber()) | |
.pipe(concat('language.js')) | |
.pipe(gulp.dest(path.build.language)) | |
}); | |
gulp.task('build', [ | |
'html:build', | |
'js:build', | |
'style:build', | |
'fonts:build', | |
'flash:build', | |
'image:build' | |
]); | |
gulp.task('watch', function() { | |
watch([path.watch.html], function(event, cb) { | |
gulp.start('html:build'); | |
}); | |
watch([path.watch.style], function(event, cb) { | |
gulp.start('style:build'); | |
}); | |
watch([path.watch.js], function(event, cb) { | |
gulp.start('js:build'); | |
}); | |
watch([path.watch.img], function(event, cb) { | |
gulp.start('image:build'); | |
}); | |
watch([path.watch.fonts], function(event, cb) { | |
gulp.start('fonts:build'); | |
}); | |
}); | |
gulp.task('default', ['build', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment