-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
105 lines (79 loc) · 2.27 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
96
97
98
99
100
101
102
103
104
105
'use strict';
var importOnce = require('node-sass-import-once'),
path = require('path');
var options = {};
options.rootPath = __dirname + '/';
options.theme = {
root: options.rootPath,
sass: {
root: options.rootPath + 'src/sass/',
library: options.rootPath + 'src/sass/_library/',
dist: options.rootPath + 'dist/css/'
}
};
options.sass = {
importer: importOnce,
includePaths: [
options.theme.sass.library,
options.rootPath + 'node_modules/breakpoint-sass/stylesheets'
],
outputStyle: 'compressed'
};
options.autoprefixer = {
browsers: [
'last 2 versions',
'> 2%'
]
};
options.gulpWatchOptions = {};
// Load Gulp and tools we will use.
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
del = require('del'),
sass = require('gulp-sass');
// Default task
gulp.task('default', ['build']);
gulp.task('build', ['styles']);
// Build CSS
var sassMain = [
options.theme.sass.root + '**/*.scss',
'!' + options.theme.sass.root + '**/_*.scss'
];
gulp.task('styles', ['clean:css', 'styles:main:min'], function () {
options.sass.outputStyle = 'expanded';
return gulp.src(sassMain)
.pipe(sass(options.sass).on('error', sass.logError))
.pipe($.autoprefixer(options.autoprefixer))
.pipe($.size({showFiles: true}))
.pipe(gulp.dest(options.theme.sass.dist));
});
gulp.task('styles:main:min', function () {
options.sass.outputStyle = 'compressed';
return gulp.src(sassMain)
.pipe($.sourcemaps.init())
.pipe(sass(options.sass).on('error', sass.logError))
.pipe($.autoprefixer(options.autoprefixer))
.pipe($.cleanCss({level: 2}))
.pipe($.size({showFiles: true}))
.pipe($.rename({
suffix: '.min'
}))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest(options.theme.sass.dist));
});
// Clean all directories.
gulp.task('clean', ['clean:css']);
// Clean CSS files.
gulp.task('clean:css', function () {
return del([
options.theme.sass.dist + '**/*.css',
options.theme.sass.dist + '**/*.map'
], {force: true});
});
// Watch for changes and rebuild.
gulp.task('watch', ['watch:css'], function () {
$.livereload.listen();
});
gulp.task('watch:css', ['styles'], function () {
return gulp.watch(options.theme.sass.root + '**/*.scss', options.gulpWatchOptions, ['styles']);
});