Last active
August 29, 2015 14:19
-
-
Save fnky/08ce48bfbc6292b4ae35 to your computer and use it in GitHub Desktop.
Resize retina files to normal with gulp
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
gulp = require('gulp') | |
newer = require('gulp-newer') | |
unretina = require('gulp-unretina') | |
rename = require('gulp-rename') | |
###* | |
# Transforms the path from e.g. asset_2x.png to asset.png | |
# @param {String} suffix The suffix to remove | |
### | |
transformPath = (suffix) -> | |
(relativePath) -> | |
p = relativePath.split('.') | |
p[0].substring(0, p[0].length - suffix.length) + '.' + p[1] | |
gulp.task 'unretina', -> | |
gulp.src('./src/**/*_2x.{png,jpg}') | |
.pipe(newer( | |
dest: './dist' | |
map: transformPath('_2x') | |
)) | |
.pipe unretina(suffix: '_2x') | |
.pipe gulp.dest('./dist') |
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 newer = require('gulp-newer'); | |
var unretina = require('gulp-unretina'); | |
var rename = require('gulp-rename'); | |
/** | |
* Transforms the path from e.g. asset_2x.png to asset.png | |
* @param {String} suffix The suffix to remove | |
*/ | |
function transformPath(suffix) { | |
return function(relativePath) { | |
var p = relativePath.split('.'); | |
return p[0].substring(0, p[0].length - suffix.length) + '.' + p[1]; | |
} | |
} | |
gulp.task('unretina', function () { | |
return gulp.src('./src/**/*_2x.{png,jpg}') | |
.pipe(newer({ | |
dest: './dist', | |
map: transformPath('_2x') | |
})) | |
.pipe(unretina({ | |
suffix: '_2x' | |
})) | |
.pipe(gulp.dest('./dist')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment