-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
97 lines (86 loc) · 2.17 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
const {
src,
dest,
parallel,
series,
watch
} = require('gulp');
// Load plugins
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const cssnano = require('gulp-cssnano');
const concat = require('gulp-concat');
const clean = require('gulp-clean');
const imagemin = require('gulp-imagemin');
const changed = require('gulp-changed');
const browsersync = require('browser-sync').create();
// Clean assets
function clear() {
return src('./assets/*', {
read: false
})
.pipe(clean());
}
// JS function
function js() {
const source = './src/js/*.js';
return src(source)
.pipe(changed(source))
.pipe(concat('bundle.js'))
.pipe(uglify())
.pipe(rename({
extname: '.min.js'
}))
.pipe(dest('./assets/js/'))
.pipe(browsersync.stream());
}
// CSS function
function css() {
const source = './src/scss/**/*.scss';
return src(source)
.pipe(changed(source))
.pipe(sass())
.pipe(autoprefixer({
overrideBrowserslist: ['last 2 versions'],
cascade: false
}))
.pipe(rename({
extname: '.min.css'
}))
.pipe(cssnano())
.pipe(dest('./assets/css/'))
.pipe(browsersync.stream());
}
//HTML
function html() {
const source = "./src/**/*.html";
return src(source).pipe(dest("./assets"))
.pipe(browsersync.stream());
}
// Optimize images
function img() {
return src('./src/img/*')
.pipe(imagemin())
.pipe(dest('./assets/img'));
}
// Watch files
function watchFiles() {
watch('./src/scss/**/*.scss', css);
watch('./src/js/**/*.js', js);
watch('./src/img/*', img);
watch("./src/**/*.html", html);
}
// BrowserSync
function browserSync() {
browsersync.init({
server: {
baseDir: './assets'
},
port: 3000
});
}
// Tasks to define the execution of the functions simultaneously or in series
exports.watch = parallel(watchFiles, browserSync);
exports.default = series(clear, parallel(html, js, css, img));