Files
native/metro.config.js

47 lines
1.7 KiB
JavaScript

const path = require('path');
const fs = require('fs');
const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname);
// Performance harness (the iOS simulator tests, .github/workflows/e2e-ios.yml):
// with BULWARK_MODULE_TIMINGS set, the bundle times each module's
// evaluation (scripts/perf/module-timings.js), and BULWARK_MODULE_MAP names
// a file that receives the module ids with their source paths, so the
// harness can tell which module is which. Release builds set neither.
if (process.env.BULWARK_MODULE_TIMINGS) {
const basePolyfills = config.serializer.getPolyfills;
config.serializer.getPolyfills = (ctx) => [
...basePolyfills(ctx),
path.join(__dirname, 'scripts/perf/module-timings.js'),
];
const mapFile = process.env.BULWARK_MODULE_MAP;
if (mapFile) {
const baseFactory = config.serializer.createModuleIdFactory;
config.serializer.createModuleIdFactory = () => {
const idOf = baseFactory();
const names = {};
process.on('exit', () => {
try { fs.writeFileSync(mapFile, JSON.stringify(names)); } catch { /* best effort */ }
});
return (modulePath) => {
const id = idOf(modulePath);
names[id] = path.relative(__dirname, modulePath).split(path.sep).join('/');
return id;
};
};
}
}
// Evaluate a module when it is first used instead of all of them before the
// first render. Expo's default leaves this off; React Native's own template
// turns it on. Side-effect-only imports (`import './x'`) still run in place.
config.transformer.getTransformOptions = async () => ({
transform: {
experimentalImportSupport: true,
inlineRequires: true,
},
});
module.exports = config;