-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
85 lines (74 loc) · 2.13 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
/** @format */
'use strict';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { src, dest, series, watch, parallel } from 'gulp';
import gulpSass from 'gulp-sass';
import * as dartSass from 'sass';
import autoprefixer from 'gulp-autoprefixer';
import cleanCSS from 'gulp-clean-css';
import sourcemaps from 'gulp-sourcemaps';
import rename from 'gulp-rename';
import hologram from './gulp-hologram.js';
import livereload from 'gulp-livereload';
import * as http from 'http';
import st from 'st';
const sass = gulpSass(dartSass);
const __dirname = dirname(fileURLToPath(import.meta.url));
const DEST = './css';
const DIST = './dist';
const SASS_SOURCES = './sass/*.scss';
const STYLE_GUIDE_SOURCES = ['./sass/index.md', './doc_assets/*.html', './code_example_templates/*.erb'].concat([
SASS_SOURCES,
]);
const GENERATED_CSS = DEST + '/*.css';
function sassTask() {
return src(SASS_SOURCES)
.pipe(
sass({
outputStyle: 'compressed',
})
)
.pipe(
autoprefixer({
cascade: false,
remove: true, // Remove cruft
})
)
.pipe(dest(DEST));
}
function hologramTask(cb) {
return src(STYLE_GUIDE_SOURCES).pipe(hologram(cb)).pipe(livereload());
}
function minifyCssTask() {
return src(GENERATED_CSS)
.pipe(sourcemaps.init())
.pipe(
cleanCSS({ debug: true }, (details) => {
console.log(`
file: ${details.name}
original: ${details.stats.originalSize}
minified: ${details.stats.minifiedSize}`);
})
)
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write())
.pipe(dest(DIST));
}
function serverTask(cb) {
http.createServer(st({ path: join(__dirname), index: join('docs', 'index.html'), cache: false })).listen(8080, cb);
}
function watchTask() {
livereload.listen({ port: 3456, basePath: __dirname });
watch(SASS_SOURCES, sassTask);
watch(STYLE_GUIDE_SOURCES, hologramTask);
watch(GENERATED_CSS, minifyCssTask);
}
export {
sassTask as sass,
hologramTask as hologram,
minifyCssTask as minifyCss,
serverTask as server,
watchTask as watch,
};
export default series(sassTask, hologramTask, serverTask, watchTask);