Skip to content

Instantly share code, notes, and snippets.

@LowerDeez
Created September 28, 2017 09:19
Show Gist options
  • Save LowerDeez/6c24f62151e983ccbe4d0774fb6fc96e to your computer and use it in GitHub Desktop.
Save LowerDeez/6c24f62151e983ccbe4d0774fb6fc96e to your computer and use it in GitHub Desktop.
Django. Web-case template. Gulp-task example to minify images
import gulp from 'gulp'
import * as stylus from './tasks/stylus'
import * as templates from './tasks/templates'
import * as pub from './tasks/public'
import * as images from './tasks/images'
gulp.task('images', images.dev)
gulp.task('public', pub.dev)
gulp.task('stylus', stylus.dev)
gulp.task('templates', templates.dev)
gulp.task('watch', (done) => {
pub.watch('public')
images.watch('images')
stylus.watch('stylus')
templates.watch('templates')
done()
})
gulp.task('default', ['watch'])
import gulp from 'gulp'
import { errorPipeWrapper } from './utils'
import { P as p, R as r } from '../../paths'
export const src = [
`${p.src.public}img/**/*`,
]
export const basedir = `${p.src.public}img/`
export const glob = src
export const dest = `${r.dest}markup/static/img/`
export const dev = function (done) {
var imagemin = require('gulp-imagemin')
var cache = require('gulp-cache')
var pngquant = require('imagemin-pngquant')
errorPipeWrapper(gulp.src(src)) // Берем все изображения
.pipe(cache(imagemin({ // Сжимаем их с наилучшими настройками с учетом кеширования
interlaced: true,
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
})))
.pipe(gulp.dest(dest)) // Выгружаем на продакшен
.on('end', done)
}
export const watch = function (task) {
let watcher = require('gulp-watch')
let batch = require('gulp-batch')
watcher(glob, batch((events, done) => gulp.start(task, done)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment