forked from nicholasadamou/starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpug.js
64 lines (58 loc) · 1.7 KB
/
pug.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
'use-strict';
var gulp = require('gulp'),
$ = require('gulp-load-plugins')({ lazy: true });
var paths = require('../../paths.js'),
config = require('../../config.js')();
gulp.task('pug', function() {
var env = ((config.environment || process.env.NODE_ENV || 'development').trim().toLowerCase() !== 'production');
console.log('-> Compiling Pug Templates for ' + config.environment);
if (env) {
// Select files
gulp.src(`${paths.to.pug.in}/*.pug`)
// Prevent pipe breaking caused by errors from gulp plugins
.pipe($.plumber())
// Check which files have changed
.pipe($.changed(paths.to.pug.in, {
extension: '.html'
}))
// Compile Pug
.pipe($.pug({
basedir: `${__dirname}/${paths.to.pug.in}`,
pretty: (config.environment === 'development'),
data: {
env: config.environment,
},
}))
// Catch errors
.pipe($.errorHandle())
// Save files
.pipe(gulp.dest(paths.to.build))
} else {
// Select files
gulp.src(`${paths.to.pug.in}/*.pug`)
// Prevent pipe breaking caused by errors from gulp plugins
.pipe($.plumber())
// Check which files have changed
.pipe($.changed(paths.to.pug.in, {
extension: '.html'
}))
// Compile Pug
.pipe($.pug({
basedir: `${__dirname}/${paths.to.pug.in}`,
pretty: (config.environment === 'development'),
data: {
env: config.environment
},
}))
// Catch errors
.pipe($.errorHandle())
// Show file-size before compression
.pipe($.size({ title: 'Pug Templates Before Compression' }))
// Optomize and minify
.pipe($.htmlmin({collapseWhitespace: true}))
// Show file-size after compression
.pipe($.size({ title: 'Pug Templates After Compression' }))
// Save minified file
.pipe(gulp.dest(paths.to.build))
}
});