-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
88 lines (80 loc) · 1.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
const gulp = require("gulp");
const esbuild = require("gulp-esbuild");
function buildIife(bundle = false, minify = false) {
let outfile = "rm2";
if (bundle) outfile += ".bundle";
if (minify) outfile += ".min";
outfile += ".js";
// This extremely strange syntax creates a dynamically named function
// More info at https://stackoverflow.com/a/41854075
return {
[outfile]() {
return gulp
.src("src/index.ts")
.pipe(
esbuild({
tsconfig: "tsconfig.iife.json",
outfile,
sourcemap: "external",
format: "iife",
minify,
bundle,
target: ["es2020", "chrome58", "firefox57", "safari11"],
globalName: "rm2",
loader: {
".ts": "ts",
".json": "json",
},
})
)
.pipe(gulp.dest("dist/iife"));
},
}[outfile];
}
function cjs() {
return gulp
.src("src/**/*.ts")
.pipe(
esbuild({
tsconfig: "tsconfig.cjs.json",
sourcemap: "external",
format: "cjs",
loader: {
".ts": "ts",
".json": "json",
},
})
)
.pipe(gulp.dest("dist/cjs"));
}
function esm() {
return gulp
.src("src/**/*.ts")
.pipe(
esbuild({
tsconfig: "tsconfig.esm.json",
sourcemap: "external",
format: "esm",
loader: {
".ts": "ts",
".json": "json",
},
})
)
.pipe(gulp.dest("dist/esm"));
}
function watch() {
return gulp.watch("src/**/*.ts", bundle);
}
const iife = gulp.parallel(
buildIife(false, false),
buildIife(false, true),
buildIife(true, false),
buildIife(true, true)
);
const bundle = gulp.parallel(iife, cjs, esm);
exports.bundle = bundle;
exports.watch = gulp.series(bundle, watch);
exports.cjs = cjs;
exports.esm = esm;
exports.iife = iife;