-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetro.config.js
More file actions
98 lines (86 loc) · 3.74 KB
/
metro.config.js
File metadata and controls
98 lines (86 loc) · 3.74 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
const { getDefaultConfig } = require("expo/metro-config");
const { withNativeWind } = require("nativewind/metro");
const path = require("path");
const config = getDefaultConfig(__dirname);
// ============================================================================
// PRODUCTION OPTIMIZATIONS
// ============================================================================
const isProduction = process.env.NODE_ENV === "production";
if (isProduction) {
// Disable source maps in production for smaller bundles
// (Enable for debugging if needed)
config.serializer = {
...config.serializer,
// Source maps disabled - reduces bundle size by ~30%
createModuleIdFactory: () => (path) => {
// Use shorter module IDs in production
return require("crypto").createHash("sha256").update(path).digest("hex").substring(0, 8);
},
};
// Minification is enabled by default in Metro for production
// Tree shaking is automatic with ES modules
}
// ============================================================================
// CRITICAL: Enable require.context for expo-router route discovery
// ============================================================================
// Without this, expo-router cannot discover routes in /app directory
// and production builds will show a blank white page.
config.transformer = {
...config.transformer,
unstable_allowRequireContext: true,
};
// ============================================================================
// PERFORMANCE OPTIMIZATION: Platform-specific resolution
// ============================================================================
//
// Web bundle optimizations:
// 1. Use lightweight shim for react-native-reanimated on web (~300KB saved)
// 2. Use lightweight shim for react-native-gesture-handler on web (~200KB saved)
// 3. Use lightweight shim for expo-notifications on web (~180KB saved)
// 4. Use lightweight shim for expo-device on web (~30KB saved)
//
// IMPORTANT: Do NOT override config.resolver.sourceExts - this breaks Expo Router
// route discovery. The default includes mjs/cjs which are required.
const webResolveRequest = config.resolver.resolveRequest;
config.resolver.resolveRequest = (context, moduleName, platform) => {
// Use lightweight shim for react-native-reanimated on web
// This reduces web bundle by ~300KB while maintaining animations via CSS
if (platform === "web" && moduleName === "react-native-reanimated") {
return {
type: "sourceFile",
filePath: path.resolve(__dirname, "lib/reanimated-web-shim.tsx"),
};
}
// Use lightweight shim for react-native-gesture-handler on web (~200KB saved)
if (platform === "web" && moduleName === "react-native-gesture-handler") {
return {
type: "sourceFile",
filePath: path.resolve(__dirname, "lib/gesture-handler-web-shim.tsx"),
};
}
// Use lightweight stub for expo-notifications on web (~180KB saved).
// Web push is handled natively via PushManager API in use-push-notifications.ts.
if (platform === "web" && moduleName === "expo-notifications") {
return {
type: "sourceFile",
filePath: path.resolve(__dirname, "lib/notifications-web-shim.ts"),
};
}
// Use lightweight stub for expo-device on web (~30KB saved).
// Device detection is not meaningful in a browser context.
if (platform === "web" && moduleName === "expo-device") {
return {
type: "sourceFile",
filePath: path.resolve(__dirname, "lib/expo-device-web-shim.ts"),
};
}
// Use default resolver for everything else
if (webResolveRequest) {
return webResolveRequest(context, moduleName, platform);
}
return context.resolveRequest(context, moduleName, platform);
};
module.exports = withNativeWind(config, {
input: "./global.css",
forceWriteFileSystem: true,
});