-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
100 lines (81 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
98
99
100
'use strict';
// Set Variables
var gulp = require('gulp'),
del = require('del'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
maps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
cleancss = require('gulp-clean-css'),
htmlreplace = require('gulp-html-replace'),
autoprefixer = require('gulp-autoprefixer'),
browsersync = require('browser-sync').create();
// JS Tasks
function concatJs() {
return gulp.src([
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
'./assets/js/functions.js'
])
.pipe(maps.init())
.pipe(concat('main.js'))
.pipe(maps.write('./'))
.pipe(gulp.dest('./assets/js'))
.pipe(browsersync.stream());
}
// CSS Tasks
function compileSass() {
return gulp.src('./assets/scss/main.scss')
.pipe(maps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(maps.write('./'))
.pipe(gulp.dest('./assets/css'))
.pipe(browsersync.stream());
}
// Dist Tasks
function cleanDist() {
return del('./dist**');
}
function build() {
return gulp.src([
'./assets/img/**/*'
], {
base: './'
})
.pipe(gulp.dest('./dist'));
}
function renameSources() {
return gulp.src('./*.html')
.pipe(htmlreplace({
'js': 'assets/js/main.js',
'css': 'css/main.css'
}))
.pipe(gulp.dest('./dist'));
}
function minifyCss() {
return gulp.src('./assets/css/main.css')
.pipe(cleancss())
.pipe(rename('main.css'))
.pipe(gulp.dest('./dist/assets/css'));
}
function minifyJs() {
return gulp.src('./assets/js/main.js')
.pipe(uglify())
.pipe(rename('main.js'))
.pipe(gulp.dest('./dist/assets/js'));
}
gulp.task('dist', gulp.series(cleanDist, build, renameSources, compileSass, minifyCss, concatJs, minifyJs));
// Default Task
gulp.task('default', gulp.series(compileSass, concatJs));
// Dev Tasks
function watch() {
browsersync.init({
server: './'
});
gulp.watch('./assets/scss/**/*.scss', gulp.series(compileSass));
gulp.watch(["./assets/js/**/*.js", "!./js/main.js", '!./js/*.map'], concatJs);
gulp.watch('./**/*.html').on('change', browsersync.reload);
}
gulp.task('dev', gulp.series('default', watch));