-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathbuild.mjs
135 lines (122 loc) · 3.79 KB
/
build.mjs
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
132
133
134
135
#!/usr/bin/env node
// @ts-nocheck
import * as esbuild from 'esbuild';
import pkg from '../package.json' with { type: 'json' };
const SDK_VERSION = pkg.version || 'v?.?.?';
// UMD wrapper
// (while iife works for `<script>` loading, sadly, some environemnts use
// `require()` which needs the UMD wrapper. See MathLive #1833)
const COMPUTE_ENGINE_UMD_OPTIONS = {
banner: {
js: `/** Compute Engine ${SDK_VERSION} ${
process.env.GIT_VERSION ? ' -- ' + process.env.GIT_VERSION : ''
}*/
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComputeEngine = {}));})(this, (function (exports) { 'use strict';`,
},
footer: {
js: `Object.assign(exports, ComputeEngine); Object.defineProperty(exports, '__esModule', { value: true });}));`,
},
};
const MATH_JSON_UMD_OPTIONS = {
banner: {
js: `/** MathJSON ${SDK_VERSION} ${
process.env.GIT_VERSION ? ' -- ' + process.env.GIT_VERSION : ''
}*/
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathJson = {}));})(this, (function (exports) { 'use strict';`,
},
footer: {
js: `Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));`,
},
};
const BUILD_OPTIONS = {
banner: {
js: `/** Compute Engine ${SDK_VERSION} ${
process.env.GIT_VERSION ? ' -- ' + process.env.GIT_VERSION : ''
}*/`,
},
bundle: true,
define: {
ENV: JSON.stringify(process.env.BUILD),
SDK_VERSION: JSON.stringify(SDK_VERSION),
GIT_VERSION: JSON.stringify(process.env.GIT_VERSION || '?.?.?'),
},
loader: { '.ts': 'ts' },
sourcemap: false,
sourceRoot: '../src',
sourcesContent: false,
target: ['es2020'],
resolveExtensions: ['.ts', '.js'],
};
//
// Build the library
//
esbuild.build({
...BUILD_OPTIONS,
entryPoints: ['./src/compute-engine.ts'],
outfile: './dist/compute-engine.esm.js',
format: 'esm',
});
esbuild.build({
...BUILD_OPTIONS,
entryPoints: ['./src/compute-engine.ts'],
outfile: './dist/compute-engine.cjs',
format: 'iife',
...COMPUTE_ENGINE_UMD_OPTIONS,
globalName: 'ComputeEngine',
});
esbuild.build({
...BUILD_OPTIONS,
entryPoints: ['./src/math-json.ts'],
outfile: './dist/math-json.esm.js',
format: 'esm',
});
esbuild.build({
...BUILD_OPTIONS,
entryPoints: ['./src/math-json.ts'],
outfile: './dist/math-json.cjs',
format: 'iife',
...MATH_JSON_UMD_OPTIONS,
globalName: 'MathJson',
});
//
// Build the minified library
//
esbuild.build({
...BUILD_OPTIONS,
drop: ['debugger'],
pure: ['console.assert', 'console.log'],
minify: true,
entryPoints: ['./src/compute-engine.ts'],
outfile: './dist/compute-engine.min.esm.js',
format: 'esm',
});
esbuild.build({
...BUILD_OPTIONS,
drop: ['debugger'],
pure: ['console.assert', 'console.log'],
minify: true,
entryPoints: ['./src/compute-engine.ts'],
outfile: './dist/compute-engine.min.cjs',
format: 'iife',
...COMPUTE_ENGINE_UMD_OPTIONS,
globalName: 'ComputeEngine',
});
esbuild.build({
...BUILD_OPTIONS,
drop: ['debugger'],
pure: ['console.assert', 'console.log'],
entryPoints: ['./src/math-json.ts'],
outfile: './dist/math-json.min.esm.js',
format: 'esm',
});
esbuild.build({
...BUILD_OPTIONS,
drop: ['debugger'],
pure: ['console.assert', 'console.log'],
minify: true,
entryPoints: ['./src/math-json.ts'],
outfile: './dist/math-json.min.cjs',
format: 'iife',
...MATH_JSON_UMD_OPTIONS,
globalName: 'MathJson',
});