-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
77 lines (70 loc) · 1.94 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
const gulp = require("gulp");
const nunjucksRender = require('gulp-nunjucks-render');
const data = require('gulp-data');
const browserSync = require("browser-sync").create();
const sass = require("gulp-sass")(require("sass"));
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require("cssnano");
const minify = require("gulp-minify");
const config = {
srcHtml: "app/src/pages/**/*.+(html|njk)",
srcHtmlTmplt: "app/src/templates",
srcScss: "app/src/scss/*.scss",
srcJs: "app/src/js/*.js",
buildHtml: "app/build",
buildCss: "app/build/css",
buildJs: "app/build/js",
}
// Render html nunjuck files
function renderNunjucks() {
return gulp
.src(config.srcHtml)
.pipe(data(function() {
return require('./app/src/data.json')
}))
.pipe(nunjucksRender({
path: [config.srcHtmlTmplt]
}))
.pipe(gulp.dest(config.buildHtml))
.pipe(browserSync.stream());
}
// Compile .scss to .css file
function compileCSS() {
var plugins = [
autoprefixer(),
cssnano(),
]
return gulp
.src(config.srcScss)
.pipe(sass())
.pipe(postcss(plugins))
.pipe(gulp.dest(config.buildCss))
.pipe(browserSync.stream());
}
// Minify JS
function minifyJs() {
return gulp
.src(config.srcJs)
.pipe(minify({
ext: {
min: ".min.js"
}
}))
.pipe(gulp.dest(config.buildJs))
.pipe(browserSync.stream());
}
// Watch for changes
function watchChanges() {
browserSync.init({
server: "./app/build",
index: "index.html",
});
gulp.watch(config.srcHtml, renderNunjucks);
gulp.watch(config.srcScss, compileCSS);
gulp.watch(config.srcJs, minifyJs);
}
exports.renderNunjucks = renderNunjucks;
exports.compileCSS = compileCSS;
exports.watchChanges = watchChanges;
exports.default = watchChanges;