-
Notifications
You must be signed in to change notification settings - Fork 32
/
gulpfile.js
95 lines (83 loc) · 2.62 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
91
92
93
94
95
var gulp = require('gulp');
var gulputil = require('gulp-util');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sass = require('gulp-sass');
var nodesass = require('node-sass');
var sourcemaps = require('gulp-sourcemaps');
var rename = require('gulp-rename');
var autoprefixer = require('gulp-autoprefixer');
var pngquant = require('gulp-pngquant');
var fs = require("fs");
var btoa = require('btoa');
// handle scss inline-image
var sassFunctions = {
'inline-image' : function( src, mime, b64, done ) {
var src = src.getValue();
var mime = ('object' === typeof mime) ? mime.getValue() : 'image/'+src.split('.').pop();
var b64 = ('object' === typeof b64) ? b64.getValue() : true;
var content = fs.readFileSync(src);
var ret = 'data:' + mime + ';';
if ( b64 ) {
ret += 'base64,';
ret += btoa(content);
} else {
ret += content;
}
return new nodesass.types.String(ret);
}
}
gulp.task('styles-admin', function(){
gulp.src( './src/scss/recaptcha-options.scss' )
.pipe( sourcemaps.init() )
.pipe( sass( {
functions: sassFunctions,
outputStyle: 'nested'
} ).on('error', sass.logError) )
.pipe( autoprefixer( {
browsers: ['last 3 versions'],
cascade: false
} ) )
.pipe( gulp.dest( './css/' ) )
.pipe( sass( {
functions: sassFunctions,
outputStyle: 'compressed'
} ).on('error', sass.logError) )
.pipe( autoprefixer( {
browsers: ['last 3 versions'],
cascade: false
} ) )
.pipe( rename( { suffix:'.min' } ) )
.pipe( sourcemaps.write() )
.pipe( gulp.dest( './css/' ) );
});
gulp.task('scripts-admin', function() {
gulp.src( './src/js/recaptcha-options.js' )
.pipe( gulp.dest( './js/' ) )
.pipe( sourcemaps.init() )
.pipe( uglify().on('error', gulputil.log ) )
.pipe( rename( { suffix:'.min' } ) )
.pipe( sourcemaps.write() )
.pipe( gulp.dest( './js/' ) );
gulp.src( './src/js/wp-recaptcha.js' )
.pipe( gulp.dest( './js/' ) )
.pipe( sourcemaps.init() )
.pipe( uglify().on('error', gulputil.log ) )
.pipe( rename( { suffix:'.min' } ) )
.pipe( sourcemaps.write() )
.pipe( gulp.dest( './js/' ) );
});
gulp.task( 'pngquant', function() {
gulp.src('./src/images/*.png')
.pipe( pngquant({
quality: '65-80'
}))
.pipe(gulp.dest('./src/images/compressed/'));
});
gulp.task( 'watch', function() {
gulp.watch('./src/scss/**/*.scss', ['styles-admin'] );
gulp.watch('./src/js/**/*.js', ['scripts-admin'] );
gulp.watch('./src/images/*.png', ['pngquant'] );
} );
gulp.task( 'build', ['pngquant', 'styles-admin','scripts-admin'] );
gulp.task( 'default', ['build','watch'] );