forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
79 lines (66 loc) · 2.41 KB
/
rollup.config.mjs
File metadata and controls
79 lines (66 loc) · 2.41 KB
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
import fs from 'fs';
import { version, revision } from './utils/rollup-version-revision.mjs';
import { buildJSOptions, buildTypesOption } from './utils/rollup-build-target.mjs';
/** @import { RollupOptions } from 'rollup' */
const BLUE_OUT = '\x1b[34m';
const RED_OUT = '\x1b[31m';
const BOLD_OUT = '\x1b[1m';
const REGULAR_OUT = '\x1b[22m';
const RESET_OUT = '\x1b[0m';
const BUILD_TYPES = /** @type {const} */ (['release', 'debug', 'profiler', 'min']);
const MODULE_FORMAT = /** @type {const} */ (['umd', 'esm']);
const BUNDLE_STATES = /** @type {const} */ (['unbundled', 'bundled']);
const envTarget = process.env.target ? process.env.target.toLowerCase() : null;
const title = [
'Building PlayCanvas Engine',
`version ${BOLD_OUT}v${version}${REGULAR_OUT}`,
`revision ${BOLD_OUT}${revision}${REGULAR_OUT}`,
`target ${BOLD_OUT}${envTarget ?? 'all'}${REGULAR_OUT}`
].join('\n');
console.log(`${BLUE_OUT}${title}${RESET_OUT}`);
if (envTarget === null && fs.existsSync('build')) {
// no targets specified, clean build directory
fs.rmSync('build', { recursive: true });
}
function includeBuild(buildType, moduleFormat, bundleState) {
return envTarget === null ||
envTarget === buildType ||
envTarget === moduleFormat ||
envTarget === bundleState ||
envTarget === `${moduleFormat}:${buildType}` ||
envTarget === `${moduleFormat}:${bundleState}` ||
envTarget === `${buildType}:${bundleState}` ||
envTarget === `${moduleFormat}:${buildType}:${bundleState}`;
}
/**
* @type {RollupOptions[]}
*/
const targets = [];
BUILD_TYPES.forEach((buildType) => {
MODULE_FORMAT.forEach((moduleFormat) => {
BUNDLE_STATES.forEach((bundleState) => {
if (bundleState === 'unbundled' && moduleFormat === 'umd') {
return;
}
if (bundleState === 'unbundled' && buildType === 'min') {
return;
}
if (!includeBuild(buildType, moduleFormat, bundleState)) {
return;
}
targets.push(...buildJSOptions({
moduleFormat,
buildType,
bundleState
}));
});
});
});
if (envTarget === null || envTarget === 'types') {
targets.push(buildTypesOption());
}
if (!targets.length) {
console.error(`${RED_OUT}${BOLD_OUT}No targets found${RESET_OUT}`);
process.exit(1);
}
export default targets;