-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
89 lines (79 loc) · 2.47 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
var gulp = require('gulp'),
autoprefixer = require('autoprefixer'),
plumber = require( 'gulp-plumber' ),
watch = require( 'gulp-watch' ),
livereload = require( 'gulp-livereload' ),
minifycss = require( 'gulp-cssnano' ),
uglify = require( 'gulp-uglify' ),
rename = require( 'gulp-rename' ),
notify = require( 'gulp-notify' ),
include = require( 'gulp-include' ),
sass = require( 'gulp-sass' ),
concat = require('gulp-concat'),
postcss = require('gulp-postcss'),
mqpacker = require('css-mqpacker'),
imagemin = require('gulp-imagemin'),
sprity = require('sprity'),
gulpif = require('gulp-if'),
sourcemaps = require('gulp-sourcemaps'),
wpPot = require('gulp-wp-pot');
var onError = function( err ) {
console.log( 'An error occurred:', err.message );
this.emit( 'end' );
};
var src = './src/';
var paths = {
/* Source paths */
styles: src + 'sass/**/*.scss',
scripts: src + 'js/',
images: src + 'images/**/*',
/* Output paths */
stylesOutput: './css/',
scriptsOutput: './js/',
imagesOutput: './images/',
};
gulp.task( 'styles', function() {
return gulp.src( paths.styles, {
style: 'expanded'
} )
.pipe( plumber( { errorHandler: onError } ) )
.pipe( sass() )
.pipe(postcss([
autoprefixer({
browsers: ['last 2 version']
}),
mqpacker({
sort: true
}),
]))
.pipe( gulp.dest( paths.stylesOutput ) )
.pipe( minifycss() )
.pipe(sourcemaps.write())
.pipe( rename( { suffix: '.min' } ) )
.pipe( gulp.dest( paths.stylesOutput ) )
.pipe( notify( { message: 'Styles task complete' } ) );
});
gulp.task('scripts', function(){
return gulp.src(paths.scripts + '/*.js')
.pipe(concat('app.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.scriptsOutput))
.pipe( notify( { message: 'Script task complete' } ) );
});
gulp.task('images', function(){
return gulp.src(paths.images)
.pipe(imagemin({
optimizationLevel: 5,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(paths.imagesOutput))
.pipe( notify( { message: 'Images task complete' } ) );
});
gulp.task( 'watch', function() {
livereload.listen();
gulp.watch( paths.styles, [ 'styles' ] );
gulp.watch( paths.scripts + '/*.js', [ 'scripts' ] );
gulp.watch( paths.images, [ 'images' ] );
} );
gulp.task( 'default', [ 'watch', 'styles', 'scripts', 'images' ], function() {});