forked from google-udacity-india-scholars/mws-track-gifs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (81 loc) · 2.15 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
/**
* To use this file you need to have gulp installed. To install gulp you can use command 'npm i gulp-cli -g'.
*
* 'gulp' alone minifies code
* 'gulp clean' removes all the files and folders in prod folder
* 'gulp minify-html' minifies html
* 'gulp minify-css' minifies css
* 'gulp minify-js' minifies js
* 'gulp browser-sync' starts server
*/
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const babel = require('gulp-babel');
const htmlmin = require('gulp-htmlmin');
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const browserSync = require('browser-sync').create();
const pump = require('pump');
const clean = require('gulp-clean');
// Clean the files and folders in prod folder
gulp.task('clean', () => {
return gulp.src('prod', {read: false})
.pipe(clean());
});
gulp.task('copy', () => {
gulp.src(['manifest.json'])
.pipe(gulp.dest('prod'));
gulp.src('./icon/**/*')
.pipe(gulp.dest('prod/icon'));
gulp.src('./img/**/*')
.pipe(gulp.dest('prod/img'));
});
// Minify HTML
gulp.task('minify-html', () => {
return gulp.src('./*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('prod'));
});
// Minify CSS
gulp.task('minify-css', () => {
return gulp.src('css/*.css')
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(gulp.dest('prod/css'));
});
// Minify JS
gulp.task('minify-js', (cb) => {
pump([
gulp.src('js/*.js'),
eslint(),
eslint.format(),
eslint.failAfterError(),
babel({
presets: ['@babel/env']
}),
uglify(),
gulp.dest('prod/js')
]);
pump([
gulp.src('service-worker.js'),
eslint(),
eslint.format(),
eslint.failAfterError(),
babel({
presets: ['@babel/env']
}),
uglify(),
gulp.dest('prod')
],
cb
);
});
// Server for development that watches and reloads on file changes
gulp.task('browser-sync', () => {
browserSync.init({
server: ['./']
});
gulp.watch('css/*.css').on('change', browserSync.reload);
gulp.watch('*.html').on('change', browserSync.reload);
});
// Default task for gulp
gulp.task('default', ['copy', 'minify-html', 'minify-css', 'minify-js']);