UNPKG

adgile

Version:

An easy-to-use automated front-end setup.

59 lines (52 loc) 1.84 kB
'use strict' /** * A submodule for running the `adg build` task, * responsible for optimizing all images and exporting them to the export folder * @module task.images */ const settings = require('../settings.default'), helpers = require('../helpers/index'), chalk = require('chalk'), gulp = require('gulp'), path = require('path'), plugins = require('gulp-load-plugins')({ config: path.join(__dirname, '../package.json') }), bsTask = require('../tasks/task-browsersync'); /** * Export any file named "favicon" to the root and change to .ico for IE-support. * Next, grab all files in the images folder, except for _-files, and export them to the destination folder. * When in production, optimize the images first. * Finish by refreshing the page */ function runTask() { helpers.updateBar('Copying images'); helpers.verbose(chalk.grey('Running task "images"')); gulp.src(settings.assetsFolder + '/images/**/favicon.*') .pipe(plugins.rename({ dirname: '', extname: '.ico' })) .pipe(gulp.dest(config.export_misc)); const destPath = config.export_assets + '/' + settings.assetsFolder + '/images'; return gulp.src([ settings.assetsFolder + '/images/**/*', '!**/_*' ]) .pipe(plugins.plumber()) .pipe(plugins.newer(destPath)) .pipe(plugins.if(settings.isProduction, plugins.imagemin([ plugins.imagemin.optipng({optimizationLevel: 3}), plugins.imagemin.mozjpeg({progressive: true}), plugins.imagemin.gifsicle({interlaced: true, optimizationLevel: 2}), plugins.imagemin.svgo({ plugins: [ {removeViewBox: true}, {cleanupIDs: false} ] }) ]))) .pipe(gulp.dest(destPath)) .pipe(plugins.if(settings.livereload, bsTask.refresh(true))) ; } module.exports = { runTask }