This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.ts
145 lines (134 loc) · 4.94 KB
/
rollup.config.ts
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
136
137
138
139
140
141
142
143
144
145
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import { nodeResolve, type RollupNodeResolveOptions } from '@rollup/plugin-node-resolve';
import type { RollupOptions, RollupWarning } from 'rollup';
export default [
{
input: 'electron/electron.ts',
output: output('dist/ares.js'),
plugins: plugins('electron/tsconfig.json', {
exportConditions: ['node'],
ignoreDynamicRequires: true
}),
external: ['electron'],
onwarn(warning: RollupWarning, show: (warning: RollupWarning | string) => void) {
if (warning.code === 'CIRCULAR_DEPENDENCY') {
if (warning.message.includes('node_modules/conf/node_modules')) return;
if (warning.message.includes('node_modules/wkx/lib')) return;
if (warning.message.includes('node_modules/sequelize')) return;
if (warning.message.includes('node_modules/semver')) return;
}
show(warning);
}
},
{
input: 'electron/child-process/fetch-world-data.ts',
output: output('dist/child-process/fetch-world-data.js'),
plugins: plugins('electron/tsconfig.json', {
exportConditions: ['node'],
ignoreDynamicRequires: true
}),
external: ['electron']
},
{
input: 'ipc/index.ts',
output: output('dist/ipc-tw.js', 'iife'),
plugins: plugins('ipc/tsconfig.json'),
external: ['electron']
},
...workers()
];
function output(file: string, format: 'cjs' | 'iife' = 'cjs') {
return {
file,
format,
generatedCode: 'es2015'
} as const;
}
type PluginOptions = {
exportConditions?: RollupNodeResolveOptions['exportConditions'];
ignoreDynamicRequires?: NonNullable<Parameters<typeof commonjs>[0]>['ignoreDynamicRequires'];
};
function plugins(tsconfig: string, options: PluginOptions = {}) {
const extensions = ['.mjs', '.js', '.mts', '.ts', '.json'];
const nodeResolveOptions: RollupNodeResolveOptions = { extensions };
if (Array.isArray(options.exportConditions)) {
nodeResolveOptions.exportConditions = options.exportConditions;
}
const commonjsOptions: NonNullable<Parameters<typeof commonjs>[0]> = {};
if (typeof options.ignoreDynamicRequires === 'boolean') {
commonjsOptions.ignoreDynamicRequires = options.ignoreDynamicRequires;
}
return [
nodeResolve(nodeResolveOptions),
commonjs({ ignoreDynamicRequires: true }),
json(),
typescript({ tsconfig })
];
}
function workers(): RollupOptions[] {
const workerPlugins = plugins('worker/tsconfig.json');
return [
{
input: 'worker/tribal/groups/add-villages-to-group.ts',
output: output('dist/worker/tribal/add-villages-to-group.js'),
plugins: workerPlugins,
external: ['electron']
},
{
input: 'worker/tribal/groups/create-static-group.ts',
output: output('dist/worker/tribal/create-static-group.js'),
plugins: workerPlugins,
external: ['electron']
},
{
input: 'worker/tribal/units/count-troops.ts',
output: output('dist/worker/tribal/count-troops.js'),
plugins: workerPlugins,
external: ['electron']
},
{
input: 'worker/tribal/ally/fetch-diplomacy.ts',
output: output('dist/worker/tribal/fetch-diplomacy.js'),
plugins: workerPlugins,
external: ['electron']
},
{
input: 'worker/tribal/world/fetch-world-config.ts',
output: output('dist/worker/tribal/fetch-world-config.js'),
plugins: workerPlugins,
external: ['electron']
},
{
input: 'worker/tribal/world/fetch-world-units.ts',
output: output('dist/worker/tribal/fetch-world-units.js'),
plugins: workerPlugins,
external: ['electron']
},
{
input: 'worker/tribal/groups/get-village-groups.ts',
output: output('dist/worker/tribal/get-village-groups.js'),
plugins: workerPlugins,
external: ['electron']
},
{
input: 'worker/tribal/incomings/handle-incomings.ts',
output: output('dist/worker/tribal/handle-incomings.js'),
plugins: workerPlugins,
external: ['electron']
},
{
input: 'worker/tribal/snob/mint-coin.ts',
output: output('dist/worker/tribal/mint-coin.js'),
plugins: workerPlugins,
external: ['electron']
},
{
input: 'worker/web/groups/calc-safe-zone-villages.ts',
output: output('dist/worker/web/calc-safe-zone-villages.js'),
plugins: workerPlugins,
external: ['electron']
}
];
}