-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.mjs
90 lines (84 loc) · 2.67 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import fg from 'fast-glob';
import path from 'path';
import clear from 'rollup-plugin-clear';
import typescript from 'rollup-plugin-typescript2';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const projectRootDir = path.resolve(__dirname);
const scriptLimit = 10_000_000; // 10mb
const megaByte = 1_000_000;
let targetArena = '';
if (process.argv[3] === '--config-') {
targetArena = process.argv[4] || ''; // dynamic mode
} else if (process.argv[3] === '--environment') {
targetArena = process.env.DEST;
}
const arenas = fg.sync(`src/arena_*${targetArena}*`, {
onlyDirectories: true,
});
if (arenas.length === 0) {
throw new Error(`No arenas found in src matching '${targetArena}'`);
} else {
const tag = arenas.length > 1 ? 's' : '';
if (targetArena === '') {
console.log(`Building all ${arenas.length} arena${tag}.`);
} else {
console.log(`Building ${arenas.length} arena${tag} for target '${targetArena}'`);
}
}
const getOptions = arena => {
return {
input: `${arena}/main.ts`,
external: [
'arena/season_beta/capture_the_flag/basic/prototypes',
'arena/season_beta/collect_and_control/basic/prototypes',
'arena/season_beta/collect_and_control/basic/constants',
'arena/season_beta/collect_and_control/advanced/constants',
'game',
'game/constants',
'game/path-finder',
'game/prototypes',
'game/utils',
'game/visual',
],
output: {
dir: arena.replace('src/', 'dist/'),
format: 'esm',
sourcemap: false,
entryFileNames: '[name].mjs',
paths: srcPath => {
if (srcPath.startsWith('game') || srcPath.startsWith('arena')) {
return `/${srcPath}`;
}
},
},
plugins: [
clear({ targets: arenas.map(v => v.replace('src/', 'dist/')) }),
alias({
entries: [
{
find: 'common',
replacement: path.resolve(projectRootDir, 'src/common'),
},
],
}),
resolve({ rootDir: 'src' }),
commonjs(),
typescript({ tsconfig: './tsconfig.json' }),
{
generateBundle(_options, bundle) {
for (const [fileName, { code }] of Object.entries(bundle)) {
if (fileName === 'main.mjs' && code && code.length >= scriptLimit * 0.98) {
console.log(`Warning: Script limit is ${scriptLimit / megaByte}mb, output is ${code.length} bytes`);
}
}
},
},
],
};
};
export default arenas.map(getOptions);