-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
160 lines (150 loc) · 4.05 KB
/
Copy pathrollup.config.js
File metadata and controls
160 lines (150 loc) · 4.05 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'
import styles from "rollup-plugin-styler";
import shaders from './rollup/rollup-plugin-shaders.js'
import textureAtlas from './rollup/rollup-plugin-texture-atlas.js'
import globImport from './rollup/rollup-plugin-glob-import.js'
import copy from 'rollup-plugin-copy'
import replace from '@rollup/plugin-replace';
import path from 'path'
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const production = !!process.env.PRODUCTION;
const projects = process.env.PROJECTS?.split(",") ?? [
'client',
'launcher',
'server',
'tests',
'engine-editor'
];
const projectRootDir = path.resolve(__dirname);
const project = (projectName) => {
return projects.indexOf(projectName) !== -1;
}
const sharedPlugins = (side) => [
alias({
entries: [
{
find: 'src',
replacement: path.resolve(projectRootDir, 'src')
},
{
find: 'textures',
replacement: path.resolve(projectRootDir, 'src/client/textures')
}
]
}),
globImport({
format: 'textures'
}),
json(),
resolve({
extensions: ['.ts', '.tsx', '.js', '.json'],
}),
typescript({
// cacheDir: '.rollup.' + side + '.tscache'
}),
commonjs(),
replace({
preventAssignment: false,
'process.env.NODE_ENV': production ? '"production"' : '"development"'
}),
production && terser(),
]
const serverBuild = (config) => {
if(!config) return []
return [{
input: config.entry,
output: {
file: config.output,
format: 'es',
sourcemap: true
},
external: [/node_modules/],
plugins: [
...sharedPlugins("server"),
copy({
targets: [
{ src: "src/client/web/static/*", dest: "dist/resources/web/static" },
{ src: "src/client/web/views/*", dest: "dist/resources/web/views" },
{ src: "src/server/preferences/default.json", dest: 'dist/resources/', rename: 'default-preferences.json' },
{ src: "src/server/maps", dest: 'dist/resources/' },
{ src: "src/server/scripts", dest: 'dist/resources/' }
],
copyOnce: true
})
]
}]
}
const clientBuild = (config) => {
if(!config) return []
let texturesPath = "src/client/textures/"
let texturesExtension = ".texture.png"
return [{
input: config.entry,
output: {
file: config.output,
format: 'iife',
sourcemap: true,
assetFileNames: '[name][extname]',
},
plugins: [
...sharedPlugins("client"),
shaders({
include: ["**/*.glsl"]
}),
config.atlasOutput && textureAtlas({
include: [texturesPath + "**/*" + texturesExtension],
output: config.atlasOutput,
idTransformer: (id) => {
return id.substring(texturesPath.length, id.length - texturesExtension.length)
}
}),
config.stylesOutput && styles({
mode: ["extract", config.stylesOutput]
}),
...(config.plugins ?? [])
]
}]
}
export default [
...clientBuild(project('launcher') && {
entry: 'src/client/game-launcher/index.ts',
output: 'dist/resources/web/static/index.js',
// TODO: sass plugin uses fs.writeFileSync directly. Consider opening a PR
stylesOutput: 'styles/launcher-styles.css'
}),
...clientBuild(project('client') && {
entry: 'src/client/index.ts',
output: 'dist/resources/web/static/main.js',
atlasOutput: 'textures',
stylesOutput: 'styles/styles.css'
}),
...serverBuild(project('server') && {
entry: 'src/server/main.ts',
output: 'dist/index.js'
}),
...serverBuild(project('tests') && {
entry: 'test/test.ts',
output: 'test/test.js'
}),
...clientBuild(project('engine-editor') && {
entry: 'src/tools/engine-editor/index.ts',
output: 'dist/resources/web/static/tools/engine-editor/index.js',
stylesOutput: 'styles.css',
atlasOutput: 'textures',
plugins: [
copy({
targets: [
{ src: "src/tools/engine-editor/ui/index.html", dest: "dist/resources/web/static/tools/engine-editor" }
],
copyOnce: true
})
]
}),
];