-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
367 lines (357 loc) · 11.4 KB
/
Copy pathwebpack.config.js
File metadata and controls
367 lines (357 loc) · 11.4 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
import { execSync } from "child_process";
import CopyPlugin from "copy-webpack-plugin";
import dotenv from "dotenv";
import ESLintPlugin from "eslint-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import { createRequire } from "module";
import path from "path";
import { fileURLToPath } from "url";
import webpack from "webpack";
const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Load .env so DefinePlugin can inject client-side env values
dotenv.config();
// Get git commit hash - handle Vercel environment (no .git directory)
let gitCommit = process.env.GIT_COMMIT ?? process.env.VERCEL_GIT_COMMIT_SHA;
if (!gitCommit) {
try {
gitCommit = execSync("git rev-parse HEAD").toString().trim();
} catch (error) {
gitCommit = "unknown";
}
}
export default async (env, argv) => {
const isProduction = argv.mode === "production";
// Allow configuring remote server for local development
const GAME_SERVER_HOST = process.env.GAME_SERVER_HOST ?? "localhost";
const GAME_SERVER_PROTOCOL = process.env.GAME_SERVER_PROTOCOL ?? "http";
// Log all critical environment variables
console.log("\n" + "=".repeat(80));
console.log("🚀 WEBPACK BUILD CONFIGURATION");
console.log("=".repeat(80));
console.log(
`Mode: ${isProduction ? "PRODUCTION" : "DEVELOPMENT"}`,
);
console.log(`Git Commit: ${gitCommit}`);
console.log("\n📡 SERVER CONNECTION:");
console.log(` Game Server Host: ${GAME_SERVER_HOST}`);
console.log(` Game Server Protocol: ${GAME_SERVER_PROTOCOL}`);
console.log(
` Game Server URL: ${GAME_SERVER_PROTOCOL}://${GAME_SERVER_HOST}:3000`,
);
console.log("\n⛓️ BLOCKCHAIN CONFIGURATION:");
console.log(
` CONTRACT_ADDRESS: ${process.env.CONTRACT_ADDRESS ?? "❌ NOT SET (will use default)"}`,
);
console.log(
` RPC_URL: ${process.env.RPC_URL ?? "❌ NOT SET (will use default)"}`,
);
console.log(
` WS_HOST: ${process.env.WS_HOST ?? "window.location.host (default)"}`,
);
console.log("\n🔐 AUTHENTICATION:");
console.log(
` PRIVY_APP_ID: ${process.env.PRIVY_APP_ID ? "✅ SET" : "❌ NOT SET"}`,
);
console.log(
` API_DOMAIN: ${process.env.API_DOMAIN ?? "localhost:8787 (default)"}`,
);
console.log("\n💳 PAYMENTS:");
console.log(
` STRIPE_PUBLISHABLE_KEY: ${process.env.STRIPE_PUBLISHABLE_KEY ? "✅ SET" : "❌ NOT SET"}`,
);
console.log("=".repeat(80) + "\n");
// Validate critical env vars
const errors = [];
if (!process.env.CONTRACT_ADDRESS) {
errors.push(
"⚠️ CONTRACT_ADDRESS not set - tournaments will use default address!",
);
}
if (!process.env.PRIVY_APP_ID) {
errors.push("⚠️ PRIVY_APP_ID not set - wallet features may not work!");
}
if (errors.length > 0) {
console.error("\n❌ ENVIRONMENT WARNINGS:");
errors.forEach((e) => console.error(` ${e}`));
console.error("\n Set missing variables before building:");
console.error(` export CONTRACT_ADDRESS=0xYourAddress`);
console.error(` export PRIVY_APP_ID=your-app-id`);
console.error(` npm run start:client:remote\n`);
}
return {
entry: "./src/client/Main.ts",
output: {
publicPath: "/",
filename: "js/[name].[contenthash].js", // Added content hash
path: path.resolve(__dirname, "static"),
clean: isProduction,
},
module: {
rules: [
{
test: /\.bin$/,
type: "asset/resource", // Changed from raw-loader
generator: {
filename: "binary/[name].[contenthash][ext]", // Added content hash
},
},
{
test: /\.txt$/,
type: "asset/source",
},
{
test: /\.md$/,
type: "asset/resource", // Changed from raw-loader
generator: {
filename: "text/[name].[contenthash][ext]", // Added content hash
},
},
{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true,
},
},
],
exclude: [/node_modules/, /src\/server/, /src\/scripts/],
},
{
test: /\.css$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
importLoaders: 1,
},
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: ["tailwindcss", "autoprefixer"],
},
},
},
],
},
{
test: /\.(webp|png|jpe?g|gif)$/i,
type: "asset/resource",
generator: {
filename: "images/[name].[contenthash][ext]", // Added content hash
},
},
{
test: /\.html$/,
use: ["html-loader"],
},
{
test: /\.svg$/,
type: "asset/resource", // Changed from asset/inline for caching
generator: {
filename: "images/[name].[contenthash][ext]", // Added content hash
},
},
{
test: /\.(woff|woff2|eot|ttf|otf|xml)$/,
type: "asset/resource", // Changed from file-loader
generator: {
filename: "fonts/[name].[contenthash][ext]", // Added content hash and fixed path
},
},
{
test: /\.(mp3|wav|ogg)$/i,
type: "asset/resource",
generator: {
filename: "sounds/[name].[contenthash][ext]",
},
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
alias: {
"protobufjs/minimal": path.resolve(
__dirname,
"node_modules/protobufjs/minimal.js",
),
"process/browser": require.resolve("process/browser.js"),
process: require.resolve("process/browser.js"),
},
fallback: {
buffer: require.resolve("buffer/"),
stream: require.resolve("stream-browserify"),
},
},
externals: {
"@coinbase/cdp-sdk": "commonjs @coinbase/cdp-sdk",
"@coinbase/cdp-sdk/auth": "commonjs @coinbase/cdp-sdk/auth",
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/client/index.html",
filename: "index.html",
// Add optimization for HTML
minify: isProduction
? {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
}
: false,
}),
new webpack.DefinePlugin({
"process.env.WEBSOCKET_URL": JSON.stringify(
isProduction ? "" : "localhost:3000",
),
"process.env.GAME_ENV": JSON.stringify(isProduction ? "prod" : "dev"),
"process.env.GIT_COMMIT": JSON.stringify(gitCommit),
"process.env.STRIPE_PUBLISHABLE_KEY": JSON.stringify(
process.env.STRIPE_PUBLISHABLE_KEY,
),
"process.env.API_DOMAIN": JSON.stringify(process.env.API_DOMAIN),
"process.env.PRIVY_APP_ID": JSON.stringify(process.env.PRIVY_APP_ID),
"process.env.CONTRACT_ADDRESS": JSON.stringify(
process.env.CONTRACT_ADDRESS,
),
"process.env.RPC_URL": JSON.stringify(process.env.RPC_URL),
"process.env.WS_HOST": JSON.stringify(process.env.WS_HOST),
__PRIVY_APP_ID__: JSON.stringify(process.env.PRIVY_APP_ID ?? ""),
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
process: "process/browser",
}),
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, "resources"),
to: path.resolve(__dirname, "static"),
noErrorOnMissing: true,
},
{
from: path.resolve(__dirname, "proprietary"),
to: path.resolve(__dirname, "static"),
noErrorOnMissing: true,
},
],
options: { concurrency: 100 },
}),
new ESLintPlugin({
context: __dirname,
}),
],
optimization: {
// Add optimization configuration for better caching
runtimeChunk: "single",
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: "vendors",
chunks: "all",
},
},
},
},
devServer: isProduction
? {}
: {
devMiddleware: { writeToDisk: true },
static: {
directory: path.join(__dirname, "static"),
},
historyApiFallback: true,
compress: true,
port: 9000,
proxy: [
// WebSocket proxies
{
context: ["/socket"],
target: `ws://${GAME_SERVER_HOST}:3000`,
ws: true,
changeOrigin: true,
logLevel: "debug",
},
// Worker WebSocket proxies - using direct paths without /socket suffix
{
context: ["/w0"],
target: `ws://${GAME_SERVER_HOST}:3001`,
ws: true,
secure: false,
changeOrigin: true,
logLevel: "debug",
},
{
context: ["/w1"],
target: `ws://${GAME_SERVER_HOST}:3002`,
ws: true,
secure: false,
changeOrigin: true,
logLevel: "debug",
},
{
context: ["/w2"],
target: `ws://${GAME_SERVER_HOST}:3003`,
ws: true,
secure: false,
changeOrigin: true,
logLevel: "debug",
},
// Worker proxies for HTTP requests
{
context: ["/w0"],
target: `${GAME_SERVER_PROTOCOL}://${GAME_SERVER_HOST}:3001`,
pathRewrite: { "^/w0": "" },
secure: false,
changeOrigin: true,
logLevel: "debug",
},
{
context: ["/w1"],
target: `${GAME_SERVER_PROTOCOL}://${GAME_SERVER_HOST}:3002`,
pathRewrite: { "^/w1": "" },
secure: false,
changeOrigin: true,
logLevel: "debug",
},
{
context: ["/w2"],
target: `${GAME_SERVER_PROTOCOL}://${GAME_SERVER_HOST}:3003`,
pathRewrite: { "^/w2": "" },
secure: false,
changeOrigin: true,
logLevel: "debug",
},
// Original API endpoints
{
context: [
"/api/env",
"/api/game",
"/api/public_lobbies",
"/api/wallet",
"/api/join_game",
"/api/start_game",
"/api/create_game",
"/api/archive_singleplayer_game",
"/api/auth/callback",
"/api/auth/discord",
"/api/kick_player",
],
target: `${GAME_SERVER_PROTOCOL}://${GAME_SERVER_HOST}:3000`,
secure: false,
changeOrigin: true,
},
],
},
};
};