forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
70 lines (57 loc) · 1.79 KB
/
rollup.config.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
import * as fs from 'node:fs';
import { version, revision } from './utils/rollup-version-revision.mjs';
import { buildTarget } from './utils/rollup-build-target.mjs';
// unofficial package plugins
import dts from 'rollup-plugin-dts';
// custom plugins
import { runTsc } from './utils/plugins/rollup-run-tsc.mjs';
import { typesFixup } from './utils/plugins/rollup-types-fixup.mjs';
/** @typedef {import('rollup').RollupOptions} RollupOptions */
console.log(`Building PlayCanvas Engine v${version} revision ${revision}`);
/**
* @type {['release', 'debug', 'profiler', 'min']}
*/
const BUILD_TYPES = ['release', 'debug', 'profiler', 'min'];
/**
* @type {['umd', 'esm']}
*/
const MODULE_FORMAT = ['umd', 'esm'];
/**
* @type {RollupOptions[]}
*/
const TYPES_TARGET = [{
input: 'build/playcanvas/index.d.ts',
output: [{
file: 'build/playcanvas.d.ts',
footer: 'export as namespace pc;\nexport as namespace pcx;',
format: 'es'
}],
plugins: [
runTsc('tsconfig.build.json'),
typesFixup(),
dts()
]
}];
/**
* @type {RollupOptions[]}
*/
const targets = [];
const envTarget = process.env.target ? process.env.target.toLowerCase() : null;
if (envTarget === null && fs.existsSync('build')) {
// no targets specified, clean build directory
fs.rmSync('build', { recursive: true });
}
BUILD_TYPES.forEach((buildType) => {
MODULE_FORMAT.forEach((moduleFormat) => {
if (envTarget === null || envTarget === buildType || envTarget === moduleFormat || envTarget === `${moduleFormat}:${buildType}`) {
targets.push(...buildTarget({
moduleFormat,
buildType
}));
}
});
});
if (envTarget === null || envTarget === 'types') {
targets.push(...TYPES_TARGET);
}
export default targets;