-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathmetro.config.js
More file actions
62 lines (56 loc) · 2.44 KB
/
metro.config.js
File metadata and controls
62 lines (56 loc) · 2.44 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
const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname);
// ─── Tree-shaking / minification ─────────────────────────────────────────────
// Enable minification in production so unused code paths are removed by the
// Metro bundler's inline-requires and dead-code-elimination passes.
config.transformer = {
...config.transformer,
// Inline requires defers module evaluation until first use — this effectively
// implements lazy loading for heavy modules (ethers, stellar-sdk, etc.)
// and removes them from the critical path entirely when not needed.
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
};
// ─── Resolver: platform-specific module aliases ───────────────────────────────
// Prefer the ES-module (tree-shakeable) entry point for libraries that ship
// both CJS and ESM builds.
config.resolver = {
...config.resolver,
// Prioritise .mjs then .js so bundler picks up ESM where available
sourceExts: ['mjs', 'js', 'jsx', 'ts', 'tsx', 'cjs', 'json'],
};
// ─── Bundle analyser ──────────────────────────────────────────────────────────
// Run: EXPO_BUNDLE_ANALYZE=true npx expo export
// Then: npx react-native-bundle-visualizer
// Or: npx metro-viz (if installed)
//
// We wire this through an env flag so CI stays fast.
if (process.env.EXPO_BUNDLE_ANALYZE === 'true') {
// metro-bundle-analyzer serialises a stats JSON alongside the bundle
const { MetroBundleAnalyzerPlugin } = (() => {
try {
return require('metro-bundle-analyzer');
} catch {
console.warn(
'[metro] metro-bundle-analyzer not installed. ' +
'Run: npm install --save-dev metro-bundle-analyzer'
);
return { MetroBundleAnalyzerPlugin: null };
}
})();
if (MetroBundleAnalyzerPlugin) {
config.serializer = {
...config.serializer,
customSerializer: MetroBundleAnalyzerPlugin.createSerializer({
enabled: true,
openAnalyzer: false, // don't auto-open browser in CI
fileName: 'bundle-stats.json', // output alongside dist/
}),
};
}
}
module.exports = config;