-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetro.config.js
More file actions
61 lines (52 loc) · 2.38 KB
/
Copy pathmetro.config.js
File metadata and controls
61 lines (52 loc) · 2.38 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
const { getDefaultConfig } = require("expo/metro-config");
const { withNativeWind } = require("nativewind/metro");
const path = require("path");
const config = getDefaultConfig(__dirname);
// ---------------------------------------------------------------------------
// Crypto polyfill: inject before all other modules so globalThis.crypto
// is available when @noble/hashes captures it at import time.
// ---------------------------------------------------------------------------
const originalGetModules =
config.serializer?.getModulesRunBeforeMainModule ?? (() => []);
config.serializer = {
...config.serializer,
getModulesRunBeforeMainModule() {
const defaults = originalGetModules();
return [...defaults, path.resolve(__dirname, "src/crypto-polyfill.ts")];
},
};
// ---------------------------------------------------------------------------
// Resolver configuration
// ---------------------------------------------------------------------------
const TCP_SHIM = path.resolve(
__dirname,
"src/shims/react-native-tcp-socket.ts",
);
const originalResolveRequest = config.resolver?.resolveRequest;
config.resolver = {
...config.resolver,
// `wasm`: expo-sqlite ships wa-sqlite as a WebAssembly binary on web.
// `woff2`/`woff`: Bloom's web theme entry imports its four web fonts straight
// from JS (`fonts/font-urls.web`), and Metro carries neither extension in its
// default `assetExts`, so without them the web bundle fails to resolve them
// as modules — `fonts={false}` does not help, the import is module-level.
assetExts: [...(config.resolver?.assetExts ?? []), "wasm", "woff2", "woff"],
resolveRequest(context, moduleName, platform) {
// On web, replace react-native-tcp-socket with an empty shim
// (TCP sockets are not available in browsers; Electron uses IPC instead)
if (platform === "web" && moduleName === "react-native-tcp-socket") {
return { type: "sourceFile", filePath: TCP_SHIM };
}
if (originalResolveRequest) {
return originalResolveRequest(context, moduleName, platform);
}
return context.resolveRequest(context, moduleName, platform);
},
};
// NativeWind 5 (built on react-native-css) compiles both the app's own Tailwind
// classes and Bloom's — a single wrapper, no separate `withReactNativeCSS`.
module.exports = withNativeWind(config, {
input: "./global.css",
inlineRem: 16,
inlineVariables: false,
});