forked from alexwelcing/Casper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
68 lines (56 loc) · 1.77 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
const gulp = require('gulp');
const themeName = require('./package.json').name;
// gulp plugins and utils
const gutil = require('gulp-util');
const livereload = require('gulp-livereload');
const postcss = require('gulp-postcss');
const sourcemaps = require('gulp-sourcemaps');
const zip = require('gulp-zip');
// postcss plugins
const autoprefixer = require('autoprefixer');
const colorFunction = require('postcss-color-function');
const cssnano = require('cssnano');
const customProperties = require('postcss-custom-properties');
const easyimport = require('postcss-easy-import');
const swallowError = (error) => {
gutil.log(error.toString());
gutil.beep();
this.emit('end');
};
const nodemonServerInit = () => {
livereload.listen(1234);
};
gulp.task('css', () => {
const processors = [
easyimport,
customProperties,
colorFunction(),
autoprefixer(),
cssnano(),
];
return gulp.src('assets/css/*.css')
.on('error', swallowError)
.pipe(sourcemaps.init())
.pipe(postcss(processors))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/built/'))
.pipe(livereload());
});
gulp.task('build', gulp.series('css', () => nodemonServerInit()));
gulp.task('watch', () => {
gulp.watch('assets/css/**/*', gulp.series('css'));
});
gulp.task('zip', gulp.series('css', () => {
const targetDir = 'dist/';
const filename = `${themeName}.zip`;
return gulp.src([
'**/*',
'!src', '!src/**/*',
'!node_modules', '!node_modules/**/*',
'!functions', '!functions/**/*',
'!dist', '!dist/**/*',
], { followSymlinks: false })
.pipe(zip(filename))
.pipe(gulp.dest(targetDir));
}));
gulp.task('default', gulp.parallel('build', 'watch'));