-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetro.config.js
More file actions
65 lines (60 loc) · 2.02 KB
/
metro.config.js
File metadata and controls
65 lines (60 loc) · 2.02 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
const { getDefaultConfig } = require('@expo/metro-config')
const path = require('path')
// Storybook provides a helper to patch Metro config for React Native usage.
// It prevents bundling server/web-only pieces into the RN app.
let config = getDefaultConfig(__dirname)
config.resolver = config.resolver || {}
config.resolver.extraNodeModules = config.resolver.extraNodeModules || {}
// map 'storybook' to the installed @storybook folder so internal imports can resolve
config.resolver.extraNodeModules['storybook'] = path.resolve(
__dirname,
'node_modules',
'@storybook',
)
// map some Node built-ins to React Native friendly shims to avoid bundling errors
config.resolver.extraNodeModules['tty'] = path.resolve(
__dirname,
'rn-node-shims',
'tty.js',
)
config.resolver.extraNodeModules['fs'] = path.resolve(
__dirname,
'rn-node-shims',
'fs.js',
)
config.resolver.extraNodeModules['path'] = path.resolve(
__dirname,
'rn-node-shims',
'path.js',
)
config.resolver.extraNodeModules['os'] = path.resolve(
__dirname,
'rn-node-shims',
'os.js',
)
// Ensure Metro resolves .cjs files (storybook ships some CJS files)
config.resolver.sourceExts = [
...Array.from(new Set([...(config.resolver.sourceExts || []), 'cjs'])),
'.md',
]
try {
// prefer withStorybookConfig/withStorybook if available
// biome-ignore lint/correctness/noUnusedVariables: does not matter here
const { withStorybook, withStorybookConfig } =
require('@storybook/react-native/metro/withStorybook') || {}
// Some versions export the helpers directly from paths
const withSB =
require('@storybook/react-native/metro/withStorybook') ||
require('@storybook/react-native/metro/withStorybookConfig')
if (typeof withSB === 'function') {
config = withSB(config)
}
} catch (e) {
// If the helper isn't available, fall back to the patched config above.
// We still have node shims and extra ext resolution applied.
console.warn(
'withStorybook helper not applied (ok if not installed):',
e?.message || e,
)
}
module.exports = config