forked from cardinalcss/cardinalcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
121 lines (112 loc) · 2.51 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Load dependencies
var browserSync = require('browser-sync')
browserSyncReload = browserSync.reload,
del = require('del'),
gulp = require('gulp'),
gulpLoadPlugins = require('gulp-load-plugins'),
plugins = gulpLoadPlugins();
// Set browser support for gulp-autoprefixer
var browserSupport = [
'last 2 versions',
'Android >= 4.2',
'Chrome >= 25',
'Firefox >= 19',
'ie >= 9',
'iOS >= 6',
'Opera >= 12.1',
'Safari >= 6'
];
// Set paths
var paths = {
css: {
dir: './',
main: './cardinal.css',
all: './*.css'
},
less: {
dir: './',
main: './cardinal.less',
all: './**/*.less'
}
};
// Set banner
var pkg = require('./package.json'),
banner = ['/*! <%= pkg.name %> v<%= pkg.version %> | <%= pkg.license %> License | <%= pkg.homepage %> */\n'];
// Error handler
var onError = function(err) {
plugins.util.beep(); // Trigger a system beep
plugins.util.log(
plugins.util.colors.underline(plugins.util.colors.red('ERROR:'))
+ ' '
+ plugins.util.colors.cyan(err.plugin)
+ ' - '
+ err.message
); // Log a readable error message
};
// Clean (gulp clean)
gulp.task('clean', function(cb) {
del([paths.css.dir], cb);
});
// Styles (gulp styles)
gulp.task('styles', function() {
return gulp.src([
paths.less.main
])
.pipe(plugins.plumber({
errorHandler: onError
}))
.pipe(plugins.sourcemaps.init({
loadMaps: true
}))
.pipe(plugins.less())
.pipe(plugins.autoprefixer({
browsers: browserSupport
}))
.pipe(plugins.header(banner, { pkg: pkg }))
.pipe(plugins.sourcemaps.write("./"))
.pipe(gulp.dest(paths.css.dir))
.pipe(plugins.csscomb())
.pipe(plugins.size({
gzip: false,
showFiles: true,
title:'unminified css'
}))
.pipe(plugins.minifyCss({
shorthandCompacting: false,
processImport: false
}))
.pipe(plugins.size({
gzip: false,
showFiles: true,
title:'minified css'
}))
.pipe(plugins.size({
gzip: true,
showFiles: true,
title:'minified css'
}))
.pipe(plugins.rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.css.dir))
.pipe(browserSyncReload({
stream: true
}));
});
// Browser Sync (gulp browser-sync)
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: "./"
}
});
});
// Reload all Browsers
gulp.task('bs-reload', function () {
browserSyncReload();
});
// Default (gulp)
gulp.task('default', ['styles', 'browser-sync'], function() {
gulp.watch(paths.less.all, ['styles']);
gulp.watch('*.html', ['bs-reload']);
});