forked from hexojs/site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
90 lines (80 loc) · 2.25 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var cssnano = require('cssnano');
var htmlMinifierOptions = {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeOptionalTags: true,
minifyJS: true,
minifyCSS: true
};
var dirs = {
public: 'public',
screenshots: 'public/build/screenshots'
};
gulp.task('useref', function(){
var assets = $.useref.assets({
searchPath: 'public'
});
return gulp.src('public/**/*.html')
.pipe(assets)
.pipe($.if('*.css', $.postcss([
cssnano()
])))
.pipe($.if('*.css', $.minifyCss()))
.pipe($.if('*.js', $.uglify()))
.pipe($.rev())
.pipe(assets.restore())
.pipe($.useref())
.pipe($.revReplace({
prefix: '/'
}))
.pipe($.if('*.html', $.htmlMinifier(htmlMinifierOptions)))
.pipe(gulp.dest('public'));
});
gulp.task('screenshot:rev', function(){
return gulp.src('public/themes/screenshots/*.png')
.pipe($.rev())
.pipe(gulp.dest(dirs.screenshots))
.pipe($.rev.manifest())
.pipe(gulp.dest(dirs.screenshots));
});
gulp.task('screenshot:resize', ['screenshot:rev'], function(){
var resizeOptions = {
width: 400,
height: 250,
crop: true
};
return gulp.src('public/build/screenshots/*.png')
// Append "@2x" to the original images
.pipe($.rename({
suffix: '@2x'
}))
// Copy original images
.pipe(gulp.dest(dirs.screenshots))
// Resize images
.pipe($.imageResize(resizeOptions))
// Remove "@2x" in filename
.pipe($.rename(function(path){
path.basename = path.basename.replace('@2x', '');
return path;
}))
// Save resized images
.pipe(gulp.dest(dirs.screenshots));
});
gulp.task('screenshot:revreplace', ['screenshot:rev'], function(){
return gulp.src([dirs.screenshots + '/rev-manifest.json', 'public/themes/index.html'])
.pipe($.revCollector({
replaceReved: true,
dirReplacements: {
'/themes/screenshots': '/build/screenshots'
}
}))
.pipe(gulp.dest('public/themes'));
});
gulp.task('screenshot', ['screenshot:rev', 'screenshot:resize', 'screenshot:revreplace']);
gulp.task('default', ['useref', 'screenshot']);