This repository was archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
118 lines (103 loc) · 2.23 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
'use strict';
const {
src,
dest,
watch,
series
} = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const concat = require('gulp-concat');
const del = require('del');
const eslint = require('gulp-eslint');
const gulpStylelint = require('gulp-stylelint');
const minify = require('gulp-minify');
const sourcemaps = require('gulp-sourcemaps');
// For debugging, make sure gulp is installed
function defaultTask(cb) {
cb();
}
// Compile the theme styles
function themeStyles() {
return src('assets/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass.sync({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(concat('global.css'))
.pipe(sourcemaps.write(''))
.pipe(dest('dist/css'));
}
function compressThemeStyles() {
return src('assets/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass.sync({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(concat('global.min.css'))
.pipe(sourcemaps.write(''))
.pipe(dest('dist/css'));
}
// Lint Theme styles
function lintSass() {
return src('assets/scss/**/*.scss')
.pipe(gulpStylelint({
reporters: [{
formatter: 'string',
console: true
}]
}));
}
// Watch Theme style
function watchStyles(done) {
watch('assets/scss/**/*.scss',
series(themeStyles, lintSass)),
done();
}
function lintJs() {
return src('assets/js/**/*.js')
.pipe(eslint())
.pipe(eslint.format());
}
// Bundle the js added in the theme.
function themeJs() {
return src('assets/js/**/*.js')
.pipe(sourcemaps.init())
.pipe(concat('scripts.js'))
.pipe(minify({
ext: {
src: '.js',
min: '.min.js'
},
}))
.pipe(sourcemaps.write(''))
.pipe(dest('dist/js'));
}
// watch the theme scritps while linting
function watchJs(done) {
watch('assets/js/*.js',
series(themeJs, lintJs));
done();
}
function cleanJsStyles() {
return del([
'dist/js/*',
'dist/css/*'
]);
}
exports.default = defaultTask;
exports.build = series(
cleanJsStyles,
compressThemeStyles,
themeStyles,
themeJs
);
exports.production = series(
cleanJsStyles,
themeStyles,
compressThemeStyles,
themeJs
);
exports.watch = series(
watchStyles,
watchJs
);