-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.mjs
67 lines (59 loc) · 1.93 KB
/
gulpfile.mjs
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
import gulp from 'gulp';
import * as nodeSass from 'sass';
import gulpSass from 'gulp-sass';
import minifyCSS from 'gulp-csso';
import minifyJS from 'gulp-uglify';
import concat from 'gulp-concat';
import autoprefixer from 'gulp-autoprefixer';
import sourcemaps from 'gulp-sourcemaps';
import include from 'gulp-include';
const sass = gulpSass(nodeSass);
const tasks = [
'js-main',
'js-blocks',
'js-checkout',
'scss-admin',
'scss-main',
];
const watchs = [];
for (let index = 0; index < tasks.length; index++) {
let task = tasks[index];
let type = task.split("-")[0];
let file = task.split("-")[1];
if ( type === 'js' ) {
gulp.task(task, () => {
return gulp.src('src/js/'+file+'.js')
.pipe(include()).on('error', console.log)
.pipe(sourcemaps.init())
.pipe(concat(file+'.min.js'))
.pipe(minifyJS({
mangle: false
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/js'));
});
watchs.push(gulp.watch('src/js/'+file+'.js', { usePolling: true, interval: 1000 }, gulp.series(task)));
} else {
gulp.task(task, () => {
return gulp.src('src/scss/'+file+'.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(autoprefixer())
.pipe(concat(''+file+'.min.css'))
.pipe(minifyCSS())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/css'));
});
watchs.push(gulp.watch('src/scss/'+file+'.scss', { usePolling: true, interval: 1000 }, gulp.series(task)));
}
}
watchs.push(gulp.watch('src/js/*.js', { usePolling: true, interval: 1000 }, gulp.series(tasks[0])));
gulp.task('watch', () => {
for (let index = 0; index < watchs.length; index++) {
watchs[index];
}
});
gulp.task('default', async () => {
tasks.push("watch");
gulp.series(tasks)();
});