-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (55 loc) · 1.88 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
const pkg = require('./package.json')
const path = require('path')
const glob = require('glob')
const yargs = require('yargs')
const colors = require('colors')
const through = require('through2');
const sass = require('sass')
const gulp = require('gulp')
const tap = require('gulp-tap')
const connect = require('gulp-connect')
const root = yargs.argv.root || '.'
const port = yargs.argv.port || 8000
// Prevents warnings from opening too many test pages
process.setMaxListeners(20);
let cache = {};
// a custom pipeable step to transform Sass to CSS
function compileSass() {
return through.obj( ( vinylFile, encoding, callback ) => {
const transformedFile = vinylFile.clone();
sass.render({
data: transformedFile.contents.toString(),
includePaths: ['css/', 'css/theme/template']
}, ( err, result ) => {
if( err ) {
console.log( vinylFile.path );
console.log( err.formatted );
}
else {
transformedFile.extname = '.css';
transformedFile.contents = result.css;
callback( null, transformedFile );
}
});
});
}
gulp.task('css-themes', () => gulp.src(['./css/theme/source/*.scss'])
.pipe(compileSass())
.pipe(gulp.dest('./dist/theme')))
gulp.task('css-custom', () => gulp.src(['css/source/*.scss'])
.pipe(compileSass())
.pipe(gulp.dest('./dist')))
gulp.task('css', gulp.parallel('css-themes', 'css-custom'))
gulp.task('reload', () => gulp.src(['*.html', '*.md'])
.pipe(connect.reload()));
gulp.task('serve', () => {
connect.server({
root: root,
port: port,
host: '0.0.0.0',
livereload: true
})
gulp.watch(['*.html', '*.md', 'js/**'], gulp.series('reload'))
gulp.watch(['css/theme/source/*.scss'], gulp.series('css-themes', 'reload'))
gulp.watch(['css/*.scss'], gulp.series('css-custom', 'reload'))
})