-
Notifications
You must be signed in to change notification settings - Fork 23
/
gulpfile.js
98 lines (91 loc) · 2.3 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
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const sourcemaps = require('gulp-sourcemaps');
const bytediff = require('gulp-bytediff');
const browserSync = require('browser-sync').create();
const rename = require('gulp-rename');
const filter = require('gulp-filter');
const flatten = require('gulp-flatten');
const sizereport = require('gulp-sizereport');
const postcssImport = require('postcss-import');
const postcssInlineSvg = require('postcss-inline-svg');
const postcssSimpleVars = require('postcss-simple-vars');
const postcssNested = require('postcss-nested');
const postcssMixins = require('postcss-mixins');
const postcssCombineMediaQuery = require('postcss-combine-media-query');
const paths = {
srcDir: 'src/**/*',
docsDir: '*',
styles: {
src: 'src/builds/*.css',
dest: 'dist'
}
};
function build() {
return gulp
.src(paths.styles.src)
.pipe(sourcemaps.init())
.pipe(postcss([postcssImport(), postcssInlineSvg(), postcssMixins(), postcssSimpleVars(), postcssNested(), postcssCombineMediaQuery()]))
.pipe(
postcss([
autoprefixer({
env: 'legacy'
})
])
)
.pipe(sourcemaps.write('.'))
.pipe(flatten())
.pipe(gulp.dest(paths.styles.dest))
.pipe(filter('**/*.css'))
.pipe(bytediff.start())
.pipe(
postcss([
cssnano({
preset: [
'default',
{
svgo: {
floatPrecision: 0
}
}
]
})
])
)
.pipe(
rename({
suffix: '.min'
})
)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.styles.dest))
.pipe(
sizereport({
gzip: true,
total: false
})
)
.pipe(browserSync.stream());
}
function copy() {
return gulp
.src('./dist/bonsai.css')
.pipe(gulp.dest('./../bedrock-docs/themes/bedrock/assets/'));
}
function watch() {
build();
copy();
browserSync.init({
server: {
baseDir: './'
},
startPath: 'index.html'
});
gulp.watch(paths.srcDir, build);
gulp.watch(paths.srcDir, copy);
gulp.watch([paths.srcDir, paths.docsDir], browserSync.reload);
}
module.exports.build = build;
module.exports.watch = watch;