/
build.js
executable file
·45 lines (39 loc) · 1.13 KB
/
build.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
const path = require("path");
const esbuild = require("esbuild");
let outdir = path.resolve(process.cwd(), "dist");
const globalName = 'RestClient';
// esbuild doesn't support umd, here's a hack from
// https://github.com/evanw/esbuild/pull/1331#issuecomment-887877002
let footer = `(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
Object.defineProperty(exports, "__esModule", {
value: true
});
} else {
root.${globalName} = factory().${globalName};
}
}(typeof self !== 'undefined' ? self : this, () => ${globalName}));`;
let files = {
'rest-client.js': './src/rest-client.js',
'rest-client.min.js': './src/rest-client.js',
}
let builds = Object.entries(files)
.map(([filename, source]) => {
return {
entryPoints: [source],
sourcemap: true,
outfile: path.resolve(outdir, filename),
bundle: true,
platform: "browser",
format: "iife",
footer: {
js: footer,
},
globalName,
minify: /\.min\.m?js$/.test(filename)
}
})
Promise.all(builds.map(esbuild.build));