-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
gulpfile.js
131 lines (121 loc) · 2.8 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const gulp = require('gulp');
const rename = require('gulp-rename');
const size = require('gulp-size');
const terser = require('gulp-terser');
const plumber = require('gulp-plumber');
const preprocess = require('gulp-preprocess');
const rollup = require('@rollup/stream');
const source = require('vinyl-source-stream');
const pkg = require('./package.json');
require('./tasks/docs.js');
require('./tasks/typescript.js');
const context = {
GAMEOBJECT_GROUP: true,
GAMEOBJECT_ROTATION: true,
GAMEOBJECT_VELOCITY: true,
GAMEOBJECT_ACCELERATION: true,
GAMEOBJECT_TTL: true,
GAMEOBJECT_ANCHOR: true,
GAMEOBJECT_SCALE: true,
GAMEOBJECT_OPACITY: true,
SPRITE_IMAGE: true,
SPRITE_ANIMATION: true,
TEXT_AUTONEWLINE: true,
TEXT_NEWLINE: true,
TEXT_RTL: true,
TEXT_ALIGN: true,
TEXT_STROKE: true,
TILEENGINE_CAMERA: true,
TILEENGINE_DYNAMIC: true,
TILEENGINE_QUERY: true,
TILEENGINE_TILED: true,
VECTOR_SUBTRACT: true,
VECTOR_SCALE: true,
VECTOR_NORMALIZE: true,
VECTOR_DOT: true,
VECTOR_LENGTH: true,
VECTOR_DISTANCE: true,
VECTOR_ANGLE: true,
VECTOR_DIRECTION: true,
VECTOR_CLAMP: true
// DEBUG and VISUAL_DEBUG are turned off
};
const headerComment = `/**
* @preserve
* Kontra.js v${pkg.version}
*/`;
function buildIife() {
return rollup({
input: './src/kontra.defaults.js',
output: {
format: 'iife',
name: 'kontra',
strict: false,
banner: headerComment
}
})
.pipe(source('kontra.js'))
.pipe(gulp.dest('.'))
.pipe(gulp.dest('./docs/assets/js'));
}
function buildModule() {
return rollup({
input: './src/kontra.js',
output: {
format: 'es',
strict: false,
banner: headerComment
}
})
.pipe(source('kontra.mjs'))
.pipe(gulp.dest('.'));
}
function distIife() {
return gulp
.src('kontra.js')
.pipe(preprocess({ context }))
.pipe(plumber())
.pipe(terser())
.pipe(plumber.stop())
.pipe(gulp.dest('./docs/assets/js'))
.pipe(rename('kontra.min.js'))
.pipe(
size({
showFiles: true
})
)
.pipe(
size({
showFiles: true,
gzip: true
})
)
.pipe(gulp.dest('.'));
}
function distModule() {
return gulp
.src('kontra.mjs')
.pipe(preprocess({ context }))
.pipe(plumber())
.pipe(terser())
.pipe(plumber.stop())
.pipe(rename('kontra.min.mjs'))
.pipe(
size({
showFiles: true
})
)
.pipe(
size({
showFiles: true,
gzip: true
})
)
.pipe(gulp.dest('.'));
}
gulp.task('build', gulp.series(buildIife, buildModule, 'build:docs', 'build:ts'));
gulp.task('dist', gulp.series('build', distIife, distModule));
gulp.task('watch', function () {
gulp.watch('src/*.js', gulp.series('build', 'dist'));
});
gulp.task('default', gulp.series('build', 'watch'));