-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
134 lines (120 loc) · 3.44 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
var gulp = require('gulp');
var del = require('del');
var rename = require('gulp-rename');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');
var sass = require('gulp-sass');
var sassLint = require('gulp-sass-lint');
var autoprefixer = require('gulp-autoprefixer');
var cleanCSS = require('gulp-clean-css');
var jade = require('gulp-jade');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var plumber = require('gulp-plumber');
var options = {
src: {
jade: ['./src/jade/**/*.jade', '!src/jade/**/layout.jade'],
js: './src/js/**/*.js',
sass: ['./src/sass/**/*.s+(a|c)ss', '!src/sass/vendors/**/*']
},
dest: {
html: './dist/',
js: './dist/js',
css: './dist/css'
},
filesToCopy: [
{
src: './src/images/**/*.*',
dest: './dist/images'
},
{
src: './src/fonts/**/*.*',
dest: './dist/fonts'
}
],
autoprefixer: 'last 2 versions'
};
var cleanFolders = [ 'dist' ];
gulp.task('clean', function () {
return del(cleanFolders);
});
gulp.task('build:html', function() {
return gulp.src(options.src.jade)
.pipe(plumber())
.pipe(jade({pretty: true}))
.pipe(gulp.dest(options.dest.html))
.pipe(reload({stream: true}));
});
gulp.task('build:html:min', function() {
return gulp.src(options.src.jade)
.pipe(jade())
.pipe(gulp.dest(options.dest.html))
.pipe(reload({stream: true}));
});
gulp.task('build:js', function() {
return gulp.src(options.src.js)
.pipe(plumber())
.pipe(babel())
.pipe(gulp.dest(options.dest.js))
.pipe(reload({stream: true}));
});
gulp.task('build:js:min', function() {
return gulp.src(options.src.js)
.pipe(babel())
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest(options.dest.js))
.pipe(reload({stream: true}));
});
gulp.task('build:css', function() {
return gulp.src(options.src.sass)
.pipe(plumber())
.pipe(sassLint())
.pipe(sassLint.format())
.pipe(sassLint.failOnError())
.pipe(sass({outputStyle: 'expanded'})
.on('error', sass.logError))
.pipe(autoprefixer(options.autoprefixer))
.pipe(gulp.dest(options.dest.css))
.pipe(reload({stream: true}));
});
gulp.task('build:css:min', function() {
return gulp.src(options.src.sass)
.pipe(sassLint())
.pipe(sassLint.format())
.pipe(sassLint.failOnError())
.pipe(sass({outputStyle: 'compressed'})
.on('error', sass.logError))
.pipe(autoprefixer(options.autoprefixer))
.pipe(rename({suffix: '.min'}))
.pipe(cleanCSS({debug: true}, function(details) {
console.log(details.name + ': ' + details.stats.originalSize);
console.log(details.name, ': ', details.stats.minifiedSize);
}))
.pipe(gulp.dest(options.dest.css))
.pipe(reload({stream: true}));
});
gulp.task('copy', function() {
options.filesToCopy.forEach(function(file) {
gulp.src(file.src)
.pipe(gulp.dest(file.dest));
});
});
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: options.dest.html
}
});
});
gulp.task('watch', function() {
gulp.watch(options.src.js, ['build:js']);
gulp.watch(options.src.sass, ['build:css']);
gulp.watch(options.src.jade, ['build:html']);
});
gulp.task('default', ['copy', 'build:html', 'build:js', 'build:css', 'browser-sync', 'watch']);
gulp.task('build', ['default']);
gulp.task('build:min', ['copy', 'build:html:min', 'build:js:min', 'build:css:min']);
gulp.task('build:clean', ['clean', 'default']);
// @todo: add Mocha tests
// gulp.task('build:test', ['test', 'default']);