Created
July 3, 2014 16:20
-
-
Save beautyfree/9743903153c5ce28a175 to your computer and use it in GitHub Desktop.
2048
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
var gulp = require('gulp'); | |
var jade = require('gulp-jade'), | |
uglify = require('gulp-uglify'), | |
concat = require('gulp-concat'), | |
plumber = require('gulp-plumber'), | |
sass = require('gulp-sass'), | |
imagemin = require('gulp-imagemin'), | |
es = require('event-stream'), | |
rename = require('gulp-rename'); | |
var paths = { | |
templates: { | |
src: 'client/*.jade', | |
dest: 'build' | |
}, | |
scripts: { | |
src: [ | |
'client/assets/js/**/*.js' | |
], | |
dest: 'build/assets/js' | |
}, | |
scripts_concat: { | |
entities: [ | |
{ | |
filename: 'game', | |
src: ['client/assets/js/game/*.js', '!client/assets/js/game/application.js'] | |
}, | |
{ | |
filename: 'libs_external', | |
src: 'client/assets/js/libs/external/*.js' | |
} | |
], | |
dest: 'build/assets/js' | |
}, | |
styles: { | |
src: 'client/assets/css/**/*.scss', | |
dest: 'build/assets/css' | |
}, | |
images: { | |
src: 'client/assets/img/**/*', | |
dest: 'build/assets/img' | |
}, | |
moves: { | |
src: [ | |
'client/assets/lang/*.json', | |
'client/assets/fonts/*.*', | |
'client/assets/css/game/fonts/*.*', | |
'client/assets/*.xml' | |
] | |
} | |
}; | |
gulp.task('templates', function () { | |
return gulp.src(paths.templates.src) | |
.pipe(jade({ | |
pretty: false // Если нужны древовидные сорцы, в продакшене лучше вырубить(исходники скрыть и размер уменьшить) | |
})) | |
.pipe(gulp.dest(paths.templates.dest)) | |
}); | |
gulp.task('scripts', function () { | |
// Minify and copy all JavaScript | |
return gulp.src(paths.scripts.src) | |
.pipe(uglify()) | |
.pipe(gulp.dest(paths.scripts.dest)); | |
}); | |
gulp.task('scripts_concat', function () { | |
var scripts = paths.scripts_concat.entities.map(function (entity) { | |
return gulp.src(entity.src) | |
.pipe(concat(entity.filename + '.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest(paths.scripts_concat.dest)); | |
}); | |
return es.concat.apply(null, scripts); | |
}); | |
gulp.task('styles', function () { | |
return gulp.src(paths.styles.src) | |
.pipe(plumber()) | |
.pipe(sass({ | |
style: 'compressed' | |
})) | |
.pipe(gulp.dest(paths.styles.dest)); | |
}); | |
// Copy all static images | |
gulp.task('images', function () { | |
return gulp.src(paths.images.src) | |
//.pipe(imagemin({optimizationLevel: 5})) | |
.pipe(gulp.dest(paths.images.dest)); | |
}); | |
gulp.task('moves', function () { | |
return gulp.src(paths.moves.src, {base: 'client' }) | |
.pipe(gulp.dest('build')); | |
}); | |
// Rerun the task when a file changes | |
gulp.task('watch', function () { | |
gulp.watch(paths.templates.src, ['templates']); | |
gulp.watch(paths.scripts.src, ['scripts']); | |
gulp.watch(paths.scripts_concat.src, ['scripts_concat']); | |
gulp.watch(paths.styles.src, ['styles']); | |
gulp.watch(paths.images.src, ['images']); | |
gulp.watch(paths.moves.src, ['moves']); | |
}); | |
// The default task (called when you run `gulp` from cli) | |
gulp.task('default', ['templates', 'scripts', 'scripts_concat', 'styles', 'images', 'moves', 'watch']); | |
gulp.task('build', ['templates', 'scripts', 'scripts_concat', 'styles', 'images', 'moves']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment