-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
75 lines (67 loc) · 1.43 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
var gulp = require("gulp"),
sass = require("gulp-sass"),
postcss = require("gulp-postcss"),
autoprefixer = require("autoprefixer"),
cssnano = require("cssnano"),
sourcemaps = require("gulp-sourcemaps"),
pug = require("gulp-pug"),
data = require("gulp-data"),
fs = require("fs"),
browserSync = require("browser-sync").create();
var paths = {
styles: {
src: "design/scss/*.scss",
dest: "design/css",
all: "design/scss/**/*.scss"
},
html: {
src: "design/pug/*.pug",
dest: "design",
all: "design/pug/**/*.pug"
},
json: "design/json/data.json"
};
function style() {
return gulp
.src(paths.styles.src)
.pipe(sass())
.on("error", sass.logError)
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(gulp.dest(paths.styles.dest))
.pipe(browserSync.reload({ stream: true }));
}
function htmls() {
return gulp
.src(paths.html.src)
.pipe(
data(function() {
return JSON.parse(fs.readFileSync(paths.json));
})
)
.pipe(
pug({
locals: {},
pretty: true
})
)
.pipe(gulp.dest(paths.html.dest));
}
function reload(done) {
browserSync.reload();
done();
}
function watch() {
browserSync.init({
server: {
baseDir: "./design"
}
});
gulp.watch(paths.styles.all, style);
gulp.watch(paths.html.all, htmls);
gulp.watch("design/*.html", reload);
}
exports.watch = watch;
exports.style = style;
exports.htmls = htmls;
var build = gulp.parallel(htmls, style, watch);
gulp.task("default", build);