-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
107 lines (73 loc) · 2.28 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('gulp-autoprefixer');
const cleanCss = require('gulp-clean-css');
const uglify = require('gulp-uglify-es').default;
const imagemin = require('gulp-imagemin');
const htmlmin = require('gulp-htmlmin');
const del = require('del');
const runSequence = require('run-sequence');
//compile sass
gulp.task('sass', function() {
return gulp.src(['src/scss/**/*.scss'])
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(autoprefixer({
browsers: ['last 3 versions']
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('src/css'))
.pipe(browserSync.stream());
});
//move js files to src folder
gulp.task('js', function() {
return gulp.src(['node_modules/bootstrap/dist/js/bootstrap.min.js','node_modules/jquery/dist/jquery.min.js','node_modules/popper.js/dist/umd/popper.min.js'])
.pipe(gulp.dest('src/js'))
.pipe(browserSync.stream());
});
//watch sass and server
gulp.task('serve',['sass'], function() {
browserSync.init({
server: './src'
});
gulp.watch(['src/scss/*.scss'], ['sass']);
gulp.watch(['src/*.html','src/js/*.js', 'src/scss/**/*.scss'], browserSync.reload);
});
//minify css files and move to dist
gulp.task('css', function(){
return gulp.src('src/css/**/*.css')
.pipe(cleanCss())
.pipe(gulp.dest('dist/css'));
});
//minify js files and move to dist
gulp.task('uglify', function(){
return gulp.src('src/js/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
});
//copy img folder and move to dist
gulp.task('copy', function() {
gulp.src('src/img/**/*.{jpg,jpeg,png,gif}')
.pipe(gulp.dest('dist/img/'));
});
//minify html and move to dist
gulp.task('minify', function() {
return gulp.src('src/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'));
});
gulp.task('clean', function() {
del('dist');
});
gulp.task('build', function() {
runSequence('clean', ['css', 'uglify', 'copy', 'minify']);
});
//server for dist folder
gulp.task('servefordist', ['build'], function() {
browserSync.init({
server: './dist'
});
});
gulp.task('default', ['js','serve']);