-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
71 lines (65 loc) · 1.86 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
/**
* initialize variables.
* @init variables
*/
const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const terser = require('gulp-terser');
const cleanCSS = require('gulp-clean-css');
const rename = require('gulp-rename');
const livereload = require('gulp-livereload');
/**
* Gulp task to compile and minify SASS to CSS.
* @task sass
*/
gulp.task('sass', function () {
return gulp
.src('src/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/css'));
});
/**
* Gulp task to Minify main.js inside src/js and output to dist/js.
* @task js-main
*/
gulp.task('js-main', function () {
return gulp
.src('src/js/main.js')
.pipe(terser())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/js'));
});
/**
* Gulp task to Copy all JavaScript files in src/js/modules to dist/js/modules.
* @task js-modules
*/
gulp.task('js-modules', function () {
return gulp
.src('src/js/modules/**/*.js')
.pipe(gulp.dest('dist/js/modules'));
});
/**
* Gulp task to automatically reload the browser when files change on port 80.
* @task live-reload
*/
gulp.task('live-reload', function() {
livereload.listen({ port: 80 });
gulp.watch(['dist/**', '*.php', '*.html']).on('change', livereload.changed);
});
/**
* Gulp task to start gulp (run 'gulp' in the terminal)
* @task gulp
*/
gulp.task('default', gulp.series('sass', 'js-main', 'js-modules', 'live-reload'));
/**
* Gulp task to Watch for changes in SASS and JavaScript files
* @task watch
*/
gulp.task('watch', function () {
gulp.watch('src/scss/**/*.scss', gulp.series('sass'))
gulp.watch('src/js/main.js', gulp.series('js-main'))
gulp.watch('src/js/modules/**/*.js', gulp.series('js-modules'))
gulp.watch(['dist/**', '*.php', '*.html'], gulp.series('live-reload'))
});