generated from adamstddrd/grease
-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
94 lines (81 loc) · 2.48 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
const { src, dest, watch, series, parallel } = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const imagemin = require('gulp-imagemin');
const changed = require('gulp-changed');
const esbuild = require('gulp-esbuild');
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const postcssPresetEnv = require('postcss-preset-env');
const postcssImport = require('postcss-import');
const postcssImportGlob = require('postcss-import-ext-glob');
const source = '_source/_assets';
const output = '_public/assets';
/* ----------------------------------------------------------------------------
css
---------------------------------------------------------------------------- */
function buildCss() {
return src(source+'/css/main.pcss')
.pipe(sourcemaps.init())
.pipe(postcss([
postcssImportGlob(),
postcssImport(),
postcssPresetEnv({stage: 1}),
cssnano()
]))
.pipe(rename({ extname: '.css' }))
.pipe(sourcemaps.write('.'))
.pipe(dest(output)
);
}
function watchCss(){
return watch(source+'/css/**/*.pcss', buildCss);
}
/* ----------------------------------------------------------------------------
javascript
---------------------------------------------------------------------------- */
function buildJs() {
return src(source+'/js/app.js')
.pipe(esbuild({
outfile: 'app.js',
bundle: true,
sourcemap: true,
minify: true,
}))
.pipe(dest(output)
);
}
function watchJs(){
return watch(source+'/js/**/*.js', buildJs);
}
/* ----------------------------------------------------------------------------
images
---------------------------------------------------------------------------- */
const imgPath = [
source+'/images/**/*',
'!'+source+'/images/**/.*'
];
function buildImg() {
return src(imgPath)
.pipe(changed(output))
.pipe(imagemin([
imagemin.gifsicle(),
imagemin.mozjpeg(),
imagemin.optipng(),
]))
.pipe(dest(output)
);
}
function watchImg(){
return watch(imgPath, buildImg);
}
/* ----------------------------------------------------------------------------
composed tasks
---------------------------------------------------------------------------- */
const buildAll = parallel(buildCss, buildJs, buildImg);
const watchAll = parallel(watchCss, watchJs, watchImg);
exports.default = buildAll;
exports.css = buildCss;
exports.js = buildJs;
exports.img = buildImg;
exports.watch = series(buildAll, watchAll);