-
Notifications
You must be signed in to change notification settings - Fork 44
/
gulpfile.js
137 lines (123 loc) · 4.05 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"use strict";
var gulp = require('gulp'),
sass = require('gulp-sass'),
del = require('del'),
uglify = require('gulp-uglify'),
cleanCSS = require('gulp-clean-css'),
rename = require("gulp-rename"),
merge = require('merge-stream'),
htmlreplace = require('gulp-html-replace'),
autoprefixer = require('gulp-autoprefixer'),
browserSync = require('browser-sync').create();
// Clean task
gulp.task('clean', function() {
return del(['dist', 'assets/css/app.css']);
});
// Copy third party libraries from node_modules into /vendor
gulp.task('vendor:js', function() {
return gulp.src([
'./node_modules/bootstrap/dist/js/*',
'./node_modules/jquery/dist/*',
'!./node_modules/jquery/dist/core.js',
'./node_modules/popper.js/dist/umd/popper.*'
])
.pipe(gulp.dest('./assets/js/vendor'));
});
// Copy font-awesome from node_modules into /fonts
gulp.task('vendor:fonts', function() {
return gulp.src([
'./node_modules/@fortawesome/fontawesome-free/**/*',
'!./node_modules/@fortawesome/fontawesome-free/{less,less/*}',
'!./node_modules/@fortawesome/fontawesome-free/{scss,scss/*}',
'!./node_modules/@fortawesome/fontawesome-free/.*',
'!./node_modules/@fortawesome/fontawesome-free/*.{json,md}'
])
.pipe(gulp.dest('./assets/fonts/font-awesome'))
});
// vendor task
gulp.task('vendor', gulp.parallel('vendor:fonts', 'vendor:js'));
// Copy vendor's js to /dist
gulp.task('vendor:build', function() {
var jsStream = gulp.src([
'./assets/js/vendor/bootstrap.bundle.min.js',
'./assets/js/vendor/jquery.slim.min.js',
'./assets/js/vendor/popper.min.js'
])
.pipe(gulp.dest('./dist/assets/js/vendor'));
var fontStream = gulp.src(['./assets/fonts/font-awesome/**/*.*']).pipe(gulp.dest('./dist/assets/fonts/font-awesome'));
return merge (jsStream, fontStream);
})
// Copy Bootstrap SCSS(SASS) from node_modules to /assets/scss/bootstrap
gulp.task('bootstrap:scss', function() {
return gulp.src(['./node_modules/bootstrap/scss/**/*'])
.pipe(gulp.dest('./assets/scss/bootstrap'));
});
// Compile SCSS(SASS) files
gulp.task('scss', gulp.series('bootstrap:scss', function compileScss() {
return gulp.src(['./assets/scss/*.scss'])
.pipe(sass.sync({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulp.dest('./assets/css'))
}));
// Minify CSS
gulp.task('css:minify', gulp.series('scss', function cssMinify() {
return gulp.src("./assets/css/app.css")
.pipe(cleanCSS())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./dist/assets/css'))
.pipe(browserSync.stream());
}));
// Minify Js
gulp.task('js:minify', function () {
return gulp.src([
'./assets/js/app.js'
])
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./dist/assets/js'))
.pipe(browserSync.stream());
});
// Replace HTML block for Js and Css file upon build and copy to /dist
gulp.task('replaceHtmlBlock', function () {
return gulp.src(['*.html'])
.pipe(htmlreplace({
'js': 'assets/js/app.min.js',
'css': 'assets/css/app.min.css'
}))
.pipe(gulp.dest('dist/'));
});
// Configure the browserSync task and watch file path for change
gulp.task('dev', function browserDev(done) {
browserSync.init({
server: {
baseDir: "./"
}
});
gulp.watch(['assets/scss/*.scss','assets/scss/**/*.scss','!assets/scss/bootstrap/**'], gulp.series('css:minify', function cssBrowserReload (done) {
browserSync.reload();
done(); //Async callback for completion.
}));
gulp.watch('assets/js/app.js', gulp.series('js:minify', function jsBrowserReload (done) {
browserSync.reload();
done();
}));
gulp.watch(['*.html']).on('change', browserSync.reload);
done();
});
// Build task
gulp.task("build", gulp.series(gulp.parallel('css:minify', 'js:minify', 'vendor'), 'vendor:build', function copyAssets() {
return gulp.src([
'*.html',
'favicon.ico',
"assets/img/**"
], { base: './'})
.pipe(gulp.dest('dist'));
}));
// Default task
gulp.task("default", gulp.series("clean", 'build', 'replaceHtmlBlock'));