-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
99 lines (88 loc) · 2.46 KB
/
gulpfile.babel.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
// generated on 2016-07-09 using generator-webapp 2.0.0
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserSync from 'browser-sync';
import del from 'del';
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
// To compile Sass files
gulp.task('styles', () => {
return gulp.src('sass/*.scss')
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
}).on('error', $.sass.logError))
.pipe($.autoprefixer({browsers: ['> 1%', 'last 2 versions', 'Firefox ESR']}))
.pipe($.sourcemaps.write())
.pipe(gulp.dest('css'))
.pipe($.cssnano())
.pipe($.rename({ // rename file
suffix: ".min" // add *.min suffix
}))
.pipe(gulp.dest('css'))
.on('end', reload);
});
// To minify scripts
gulp.task('scripts', () => {
return gulp.src(['js/*.js', '!js/*.min.js'])
.pipe($.plumber())
.pipe($.uglify({preserveComments: 'license'}))
.pipe($.rename({
suffix: ".min"
}))
.pipe(gulp.dest('js'))
.on('end', reload);
});
function lint(files, options) {
return () => {
return gulp.src(files)
.pipe(reload({stream: true, once: true}))
.pipe($.eslint(options))
.pipe($.eslint.format())
.pipe($.if(!browserSync.active, $.eslint.failAfterError()));
};
}
gulp.task('lint', lint('js/*.js'));
// Uncomment following if you want to minify HTML files
/*
gulp.task('html', ['styles', 'scripts'], () => {
return gulp.src('*.html')
.pipe($.htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('minified-html'));
});
*/
// Task to minify images
gulp.task('images', () => {
return gulp.src('images/**/*')
.pipe($.cache($.imagemin({
progressive: true,
interlaced: true,
// don't remove IDs from SVGs, they are often used
// as hooks for embedding and styling
svgoPlugins: [{cleanupIDs: false}]
})))
.pipe(gulp.dest('images-min'));
});
// Task to serve everything with browserSync (except images)
gulp.task('serve', ['styles', 'scripts'], () => {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['./']
}
});
gulp.watch([
'*.html',
'images/**/*',
'fonts/**/*'
]).on('change', reload);
gulp.watch('sass/**/*.scss', ['styles']);
gulp.watch('js/**/*.js', ['scripts']);
});
gulp.task('default', () => {
gulp.start('serve');
});