Last active
July 17, 2016 02:33
-
-
Save Gerhard-Kanzler/4eb0443e492c12d61e67 to your computer and use it in GitHub Desktop.
gulp
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
| var gulp = require('gulp'); | |
| var concat = require('gulp-concat'); | |
| var uglify = require('gulp-uglify'); | |
| var imagemin = require('gulp-imagemin'); | |
| var minifyCSS = require('gulp-minify-css'); | |
| var autoprefixer = require('gulp-autoprefixer'); | |
| var sourcemaps = require('gulp-sourcemaps'); | |
| var please = require('gulp-pleeease'); | |
| var rename = require('gulp-rename'); | |
| var paths = { | |
| css: 'static/css/min/**/*', | |
| images: 'static/img/min/**/*', | |
| scripts: 'static/js/min/**/*.js' | |
| }; | |
| gulp.task('scripts', function () { | |
| // Minify and copy all JavaScript (except vendor scripts) | |
| return gulp.src(paths.scripts) | |
| .pipe( uglify({ preserveComments: 'none' })) | |
| .pipe( concat('libs.min.js') ) | |
| .pipe( gulp.dest('static/js') ); | |
| }); | |
| gulp.task('css', function() { | |
| gulp.src('static/css/style.css') | |
| .pipe(sourcemaps.init()) | |
| .pipe(please({ | |
| mqpacker: true, | |
| autoprefixer: {browsers: ['last 4 versions']} | |
| })) | |
| .pipe(rename({ | |
| suffix: '.min', | |
| extname: '.css' | |
| })) | |
| .pipe(sourcemaps.write('./', { | |
| sourceMappingURLPrefix: '/static/css/' | |
| })) | |
| .pipe(gulp.dest('static/css')); | |
| }); | |
| // Copy all static images | |
| gulp.task('images', function() { | |
| return gulp.src(paths.images) | |
| .pipe(imagemin({optimizationLevel: 5})) | |
| .pipe(gulp.dest('static/img')); | |
| }); | |
| // Rerun the task when a file changes | |
| gulp.task('watch', function () { | |
| gulp.watch(paths.scripts, ['scripts']); | |
| gulp.watch(paths.images, ['images']); | |
| gulp.watch(paths.css, ['css']); | |
| gulp.watch('static/css/style.css', ['css']); | |
| }); | |
| // The default task (called when you run `gulp` from cli) | |
| gulp.task('default', ['watch', 'scripts', 'images', 'css']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment