This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
92 lines (79 loc) · 2.49 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
var gulp = require('gulp'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
gutil = require('gulp-util'),
minifycss = require('gulp-minify-css'),
util = require('util'),
babel = require('gulp-babel'),
eslint = require('gulp-eslint'),
gls = require('gulp-live-server'),
uglify = require('gulp-uglify'),
sassLint = require('gulp-sass-lint');
/* Helper functions */
function throwSassError(sassError) {
throw new gutil.PluginError({
plugin: 'sass',
message: util.format(
"Sass error: '%s' on line %s of %s",
sassError.message,
sassError.line,
sassError.file
)
});
}
gulp.task('help', function() {
console.log('sass - Generate the min and unminified css from sass');
console.log('build - Generate css and docs');
console.log('watch - Watch sass files and generate unminified css');
console.log('test - Lints Sass');
console.log('html - Moves html files into build');
});
gulp.task('html', function() {
return gulp.src('src/*.html')
.pipe(gulp.dest('build'));
});
gulp.task('sasslint', function() {
var path = (gutil.env.file)? gutil.env.file : '**/*.scss';
return gulp.src('src/' + path)
.pipe(sassLint())
.pipe(sassLint.format())
.pipe(sassLint.failOnError());
});
gulp.task('sass', function() {
return gulp.src('src/scss/*.scss')
.pipe(sass({
style: 'expanded',
onError: throwSassError
}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
.pipe(gulp.dest('build/'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('build/'));
});
gulp.task('babel', function () {
return gulp.src('src/js/*.js')
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('build/'));
});
gulp.task('jslint', function() {
return gulp.src('src/**/*.js')
.pipe(eslint({
useEslintrc: true
}))
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('build', ['html', 'sasslint', 'sass', 'babel']);
gulp.task('serve', function() {
var server = gls.static('build', '8888');
server.start();
});
gulp.task('watch', function() {
gulp.watch(['src/*.html', 'src/**/*.scss', 'src/**/*.js'], ['build']);
});
gulp.task('run', ['build', 'serve', 'watch']);
gulp.task('test', ['sasslint']);
gulp.task('default', ['help']);