-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathmetro.config.js
More file actions
64 lines (57 loc) · 2.1 KB
/
metro.config.js
File metadata and controls
64 lines (57 loc) · 2.1 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
const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
const path = require('path');
const getWebMetroConfig = require('./getWebMetroConfig');
const root = path.resolve(__dirname, '../..');
const threePackagePath = path.resolve(root, 'node_modules/three');
const r3fPath = path.resolve(root, "node_modules/@react-three/fiber");
const defaultConfig = getDefaultConfig(__dirname);
const customConfig = {
watchFolders: [root],
resolver: {
...defaultConfig.resolver,
extraNodeModules: {
'three': threePackagePath,
},
resolveRequest: (context, moduleName, platform) => {
if (moduleName.startsWith('three/addons/')) {
return {
filePath: path.resolve(threePackagePath, 'examples/jsm/' + moduleName.replace('three/addons/', '') + '.js'),
type: 'sourceFile',
};
}
if (moduleName === 'three' || moduleName === 'three/webgpu') {
return {
filePath: path.resolve(threePackagePath, 'build/three.webgpu.js'),
type: 'sourceFile',
};
}
if (moduleName === 'three/tsl') {
return {
filePath: path.resolve(threePackagePath, 'build/three.tsl.js'),
type: 'sourceFile',
};
}
if (moduleName === "@react-three/fiber") {
//Just use the vanilla web build of react three fiber, not the stale "native" code path which has not been kept up to date.
return {
filePath: path.resolve(r3fPath, "dist/react-three-fiber.esm.js"),
type: "sourceFile",
};
}
// Let Metro handle other modules
return context.resolveRequest(context, moduleName, platform);
},
assetExts: [...defaultConfig.resolver.assetExts, 'glb', 'gltf', 'jpg', 'bin', 'hdr'],
},
transformer: {
...defaultConfig.transformer,
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
};
const metroConfig = mergeConfig(defaultConfig, customConfig);
module.exports = !!process.env.IS_WEB_BUILD ? getWebMetroConfig(metroConfig) : metroConfig;