-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
76 lines (63 loc) · 1.64 KB
/
gulpfile.js
File metadata and controls
76 lines (63 loc) · 1.64 KB
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
import gulp from 'gulp';
import dartSass from 'sass';
import gulpSass from 'gulp-sass';
import gulpAutoprefixer from 'gulp-autoprefixer';
import gulpConcat from 'gulp-concat';
import gulpBabel from 'gulp-babel';
import gulpUglify from 'gulp-uglify';
import browserSync from 'browser-sync';
const sass = gulpSass(dartSass);
browserSync.create();
// Build all scss files into css files and add autoprefixer
const buildStyles = () => {
return gulp
.src('./assets/sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(
gulpAutoprefixer({
overrideBrowserslist: ['last 2 versions'],
cascade: false
})
)
.pipe(gulp.dest('./assets/styles'))
.pipe(browserSync.stream());
};
// Init Browser Sync
const browserSyncInit = () => {
browserSync.init({
server: {
baseDir: './'
}
});
};
// Build Javascript code
const buildJS = () => {
return gulp
.src('./assets/scripts/**/*.js')
.pipe(gulpConcat('app.min.js'))
.pipe(
gulpBabel({
presets: ['@babel/env']
})
)
.pipe(gulpUglify())
.pipe(gulp.dest('./assets/scripts/'))
.pipe(browserSync.stream());
};
// Tasks
gulp.task('browser-sync', browserSyncInit);
gulp.task('sass', async () => {
buildStyles();
});
gulp.task('js', async () => {
buildJS();
});
// Watch for changes
const watch = () => {
gulp.watch('./assets/sass/**/*.scss', gulp.series('sass'));
gulp.watch('./**/*.html').on('change', browserSync.reload);
gulp.watch('./assets/scripts/*.js', gulp.series('js'));
};
gulp.task('watch', watch);
// Default task
gulp.task('default', gulp.parallel('watch', 'browser-sync', 'sass', 'js'));