-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathmetro.config.js
More file actions
51 lines (46 loc) · 1.79 KB
/
Copy pathmetro.config.js
File metadata and controls
51 lines (46 loc) · 1.79 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
const { getDefaultConfig } = require('expo/metro-config');
const { withPowerNativeMetroLogging } = require('@microsoft/power-apps-native-host/metro-logger');
// CUSTOMIZATION START - DO NOT REMOVE OR RENAME THE COMMENT
// Add Metro config changes in this function only.
function customizeMetroConfig(config) {
return config;
}
// CUSTOMIZATION END - DO NOT REMOVE OR RENAME THE COMMENT
const config = getDefaultConfig(__dirname);
config.resolver.sourceExts = [...config.resolver.sourceExts, 'mjs'];
config.server = {
...config.server,
enhanceMiddleware: (middleware) => withPowerNativeMetroLogging(
(req, res, next) => {
if (req.url === '/__pawrap_verify') {
res.setHeader('Content-Type', 'application/json');
res.setHeader('Access-Control-Allow-Origin', '*');
res.end(JSON.stringify({ type: 'pawrap-app', version: '1' }));
return;
}
middleware(req, res, next);
},
{ projectRoot: __dirname },
),
};
// Force a single copy of these regardless of where the importing module lives.
const _defaultResolver = config.resolver.resolveRequest;
config.resolver.resolveRequest = (context, moduleName, platform) => {
const isNodeRenderer = context.customResolverOptions?.environment === 'node';
if (
(!isNodeRenderer && (moduleName === 'react' || moduleName.startsWith('react/'))) ||
(moduleName === 'react-native' && platform !== 'web') ||
moduleName.startsWith('@babel/runtime')
) {
return {
filePath: require.resolve(moduleName, {
paths: [require('path').resolve(__dirname, 'node_modules')],
}),
type: 'sourceFile',
};
}
return _defaultResolver
? _defaultResolver(context, moduleName, platform)
: context.resolveRequest(context, moduleName, platform);
};
module.exports = customizeMetroConfig(config);