-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
93 lines (85 loc) · 2.74 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
const gulp = require('gulp');
const critical = require('critical');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();
const reload = browserSync.reload;
const babel = require('gulp-babel');
const minify = require('gulp-babel-minify');
const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const imagemin = require('gulp-imagemin');
const htmlmin = require('gulp-htmlmin');
const cache = require('gulp-cache');
const concat = require('gulp-concat');
// BROWSER-SYNC / LIVE RELOADING
gulp.task('browser-sync', () => {
browserSync.init({
server: {
baseDir: './'
},
})
});
// WATCHING FOR FILE CHANGES, THEN RELOADS
gulp.task('watch', ['browser-sync'], () => {
gulp.watch('dev/styles/**/*.scss', ['sass'])
gulp.watch('*.html', reload)
gulp.watch('dev/scripts/**/*.js', ['scripts'])
});
// HTML MINIFICATION
gulp.task('html', function () {
return gulp.src('*.html')
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('public/'))
});
// HERO/VIEWPORT INLINE STYLES WITH CRTITCAL
// RENAME INDEX-CRITIAL TO INDEX.HTML AND ADD TO SERVER IF YOU WANT TO USE THIS FEATURE
// OTHERWISE JUST USE THE MINIFIED INDEX.HTML IN THE PUBLIC FOLDER
gulp.task('critical', function () {
critical.generate({
inline: true,
base: 'public/',
src: 'index.html',
width: 1300,
height: 900,
css: 'public/styles/styles.css',
dest: 'index-critical.html',
minify: true,
extract: true
});
});
// SASS INTO CSS THEN AUTOPREFIXING THEN MINIFY
gulp.task('sass', () => {
return gulp.src('dev/styles/styles.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer('last 2 versions'))
.pipe(cleanCSS())
.pipe(gulp.dest('public/styles/'))
.pipe(reload({ stream: true }))
});
// IMAGE OPTIMIZATION
gulp.task('images', () =>
gulp.src('dev/images/*')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('public/images/'))
);
// CONCAT ALL JS SCRIPTS INTO ALL.JS // CHANGE SRC PATHS TO REFLECT YOUR SCRIPTS
// ES6 TO ES5 VIA BABEL, THEN MINIFES
gulp.task('scripts', () => {
gulp.src(['dev/scripts/smooth-scroll.js', 'dev/scripts/script.js'])
.pipe(concat('all.js'))
.pipe(babel({
presets: ['env']
}))
.pipe(minify({
mangle: {
keepClassName: true
}
}))
.pipe(gulp.dest('public/scripts/'))
.pipe(reload({ stream: true }))
});
// ALL TASKS INTO ONE INIT
// ACTIVATE BUT RUNNING 'GULP' IN THE TERMINAL
gulp.task('default', ['browser-sync', 'html', 'sass', 'scripts', 'critical', 'images', 'watch']);