-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (63 loc) · 1.77 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
'use strict';
// Gulp packages.
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var pump = require('pump');
var del = require('del');
var rename = require('gulp-rename');
// Custom settings.
var theme_name = 'theme';
// Path settings.
var paths = {
theme: './' + theme_name,
sass: './' + theme_name + '/src/sass',
css: './' + theme_name + '/dist/css',
css_maps: './maps',
js_src: './' + theme_name + '/src/js',
js_dist: './' + theme_name + '/dist/js',
js_maps: './maps'
};
var options = {
sass: {
outputStyle: 'compressed'
},
uglify: {
quote_style: 1
}
};
gulp.task('clean-css', function() {
del.sync([paths.css + '/*']);
del.sync([paths.css + '/' + paths.css_maps]);
});
gulp.task('clean-js', function() {
del.sync([paths.js_dist + '/*']);
del.sync([paths.js_dist + '/' + paths.js_maps]);
});
gulp.task('clean', ['clean-css', 'clean-js']);
gulp.task('compile-css', ['clean-css'], function() {
return gulp.src(paths.sass + '/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass(options.sass).on('error', sass.logError))
.pipe(sourcemaps.write(paths.css_maps, {sourceRoot: '../../src/sass/'}))
.pipe(gulp.dest(paths.css));
});
gulp.task('compile-js', ['clean-js'], function(cb) {
pump([
gulp.src(paths.js_src + '/*.js'),
sourcemaps.init(),
rename({suffix: '.min'}),
uglify(options.uglify),
sourcemaps.write(paths.js_maps),
gulp.dest(paths.js_dist)
],
cb
);
});
gulp.task('compile', ['compile-css', 'compile-js']);
gulp.task('watch', function() {
gulp.watch(paths.sass + '/**/*.scss', ['compile-css']);
gulp.watch(paths.js_src + '/**/*.js', ['compile-js']);
});
gulp.task('default', ['compile', 'watch']);