-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
150 lines (124 loc) · 4.6 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
'use strict';
// Include Gulp & Tools We'll Use
var gulp = require('gulp');
var runSequence = require('run-sequence');
var $ = require('gulp-load-plugins')({
rename: {
'gulp-replace-task': 'replacetask',
'gulp-watch': 'watch'
}
});
var pkg = require('./package.json');
var AUTOPREFIXER_BROWSERS = [
//
// Official browser support policy:
// http://v4-alpha.getbootstrap.com/getting-started/browsers-devices/#supported-browsers
//
'Chrome >= 35', // Exact version number here is kinda arbitrary
// Rather than using Autoprefixer's native "Firefox ESR" version specifier string,
// we deliberately hardcode the number. This is to avoid unwittingly severely breaking the previous ESR in the event that:
// (a) we happen to ship a new Bootstrap release soon after the release of a new ESR,
// such that folks haven't yet had a reasonable amount of time to upgrade; and
// (b) the new ESR has unprefixed CSS properties/values whose absence would severely break webpages
// (e.g. `box-sizing`, as opposed to `background: linear-gradient(...)`).
// Since they've been unprefixed, Autoprefixer will stop prefixing them,
// thus causing them to not work in the previous ESR (where the prefixes were required).
'Firefox >= 38', // Current Firefox Extended Support Release (ESR); https://www.mozilla.org/en-US/firefox/organizations/faq/
// Note: Edge versions in Autoprefixer & Can I Use refer to the EdgeHTML rendering engine version,
// NOT the Edge app version shown in Edge's "About" screen.
// For example, at the time of writing, Edge 20 on an up-to-date system uses EdgeHTML 12.
// See also https://github.com/Fyrd/caniuse/issues/1928
'Edge >= 12',
'Explorer >= 9',
// Out of leniency, we prefix these 1 version further back than the official policy.
'iOS >= 8',
'Safari >= 8',
// The following remain NOT officially supported, but we're lenient and include their prefixes to avoid severely breaking in them.
'Android 2.3',
'Android >= 4',
'Opera >= 12'
];
// ***** test start ***** //
var publicRelative = './';
var publicHome = require(publicRelative + 'index.json');
gulp.task('styles', function() {
var src = publicHome.css.src;
for (var i = 0; i < src.length; i++) {
src[i] = publicRelative + src[i];
};
var dist = publicRelative + publicHome.css.dist;
console.log(src);
return gulp.src(src)
.pipe($.sass({
precision: 10,
onError: console.error.bind(console, 'Sass error:')
}))
.pipe($.autoprefixer({ browsers: AUTOPREFIXER_BROWSERS, remove: false }))
.pipe(gulp.dest('.tmp'))
.pipe($.if('*.css', $.csso()))
.pipe(gulp.dest(dist))
.pipe($.size({
title: 'styles'
}));
});
gulp.task('jshint', function() {
var src = publicHome.js.src;
var srcBase = publicRelative + publicHome.js.srcBase;
for (var i = 0; i < src.length; i++) {
src[i] = publicRelative + src[i];
};
return gulp.src(src, {
base: srcBase
})
.pipe($.jshint('index.jshintrc'))
.pipe($.jshint.reporter('jshint-stylish'));
});
gulp.task('scripts', ['jshint'], function() {
var src = publicHome.js.src;
var dist = publicRelative + publicHome.js.dist;
return gulp.src(src)
.pipe($.changed(dist))
.pipe($.uglify())
.pipe(gulp.dest(dist))
.pipe($.size({
title: 'scripts'
}));
});
gulp.task('images', function() {
var src = publicHome.image.src;
for (var i = 0; i < src.length; i++) {
src[i] = publicRelative + src[i];
};
var srcBase = publicRelative + publicHome.image.srcBase;
var dist = publicRelative + publicHome.image.dist;
console.log(src);
console.log(dist);
console.log(srcBase);
return gulp.src(src, {
base: srcBase
})
.pipe($.imagemin())
.pipe(gulp.dest(dist))
.pipe($.size({
title: 'images'
}));
});
gulp.task('all', function(done) {
runSequence(['styles', 'scripts', 'images']);
done();
});
gulp.task('watch', function (cb) {
var scriptsPath = publicHome.js.src;
for (var i = 0; i < scriptsPath.length; i++) {
scriptsPath[i] = publicRelative + scriptsPath[i];
};
var stylesPath = publicHome.css.src;
for (var i = 0; i < stylesPath.length; i++) {
stylesPath[i] = publicRelative + stylesPath[i];
};
scriptsPath = scriptsPath.concat(stylesPath);
$.watch(scriptsPath, function () {
gulp.start('all');
});
});
// ***** test end ***** //