-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
executable file
·111 lines (88 loc) · 2.87 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
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict';
const gulp = require('gulp');
const del = require('del');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const terser = require('gulp-terser');
const sourcemaps = require('gulp-sourcemaps');
const nunjucksRender = require('gulp-nunjucks-render');
const log = require('gulplog');
const es = require('event-stream');
const rename = require('gulp-rename');
const gulpFn = require('gulp-fn');
const sass = require('gulp-sass');
sass.compiler = require('node-sass');
function html() {
return gulp.src('templates/**/*.+(html|nunjucks|njk)')
.pipe(nunjucksRender({
path: ['src', 'target/partials'],
// Changes nunjucks syntax because it overlaps with roll20 syntax
envOptions: {
tags: {
blockStart: '<%',
blockEnd: '%>',
variableStart: '<$',
variableEnd: '$>',
commentStart: '<#',
commentEnd: '#>'
}
}
})).pipe(gulp.dest('target'));
}
html.description = "Compile pages from templates and partials from src to target.";
var maps = true;
var minify = true;
function js(done) {
var entries = ['app.js', 'worker.js'];
var tasks = entries.map((entry) => {
var task = browserify({entries: ['./src/' + entry], debug: true})
.bundle()
.pipe(source(entry))
.pipe(rename({
extname: '.bundle.js'
}))
.pipe(buffer());
if (maps) {
task = task.pipe(sourcemaps.init({loadMaps: true}));
}
if (minify) {
task = task.pipe(terser())
.on('error', log.error);
}
if (maps) {
task = task.pipe(sourcemaps.write('./'));
}
return task
.pipe(gulp.dest('target/partials/'));
});
return es.merge.apply(null, tasks).on('end', done);
}
js.description = "Browserify, transpile, and minify JS from ./src/entry.js to target/partials/app.js";
function css() {
return gulp.src('src/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('target/'));
}
css.description = "Compile SASS from src/ to target/partials/";
function clean() {
return del([
'target/'
]);
}
clean.description = "Clean the target directory.";
const def = gulp.series(gulp.parallel(js, css), html);
def.description = "Compile everything.";
function watch() {
gulp.watch(["src/**/*", "templates/**/*"],
{ignoreInitial: false},
def
);
}
watch.description = "Watch src and templates and recompile with the default task.";
exports.html = html;
exports.clean = clean;
exports.css = css;
exports.js = js;
exports.watch = watch;
exports.default = def;