|
| 1 | +const path = require("path"); |
| 2 | +const { getDefaultConfig } = require("metro-config"); |
| 3 | + |
| 4 | +module.exports.getMinisMetroConfig = async function getMinisMetroConfig() { |
| 5 | + const { |
| 6 | + resolver: { sourceExts, assetExts }, |
| 7 | + } = await getDefaultConfig(); |
| 8 | + |
| 9 | + return { |
| 10 | + server: { |
| 11 | + port: 8082, |
| 12 | + }, |
| 13 | + transformer: { |
| 14 | + getTransformOptions: async () => ({ |
| 15 | + transform: { |
| 16 | + experimentalImportSupport: false, |
| 17 | + inlineRequires: true, |
| 18 | + }, |
| 19 | + }), |
| 20 | + babelTransformerPath: require.resolve("react-native-svg-transformer"), |
| 21 | + }, |
| 22 | + resolver: { |
| 23 | + assetExts: assetExts.filter((ext) => ext !== "svg"), |
| 24 | + sourceExts: [...sourceExts, "svg"], |
| 25 | + platforms: ["ios", "android"], |
| 26 | + resolveRequest: (context, moduleName, platform) => { |
| 27 | + // use a custom path instead of a relative import to load the mini manifest |
| 28 | + if (moduleName === "minis:manifest") { |
| 29 | + const manifestPath = path.join(process.cwd(), "src", "manifest.json"); |
| 30 | + try { |
| 31 | + return { |
| 32 | + filePath: require.resolve(manifestPath), |
| 33 | + type: "sourceFile", |
| 34 | + }; |
| 35 | + } catch (err) { |
| 36 | + // This shouldn't really happen, the CLI would explode before actually launching metro. |
| 37 | + console.warn(`Your manifest file could not be found in path ${manifestPath}`); |
| 38 | + return { type: "empty" }; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + // Chain to the standard Metro resolver for modules other than the manifest. |
| 43 | + return context.resolveRequest(context, moduleName, platform); |
| 44 | + }, |
| 45 | + }, |
| 46 | + }; |
| 47 | +}; |
0 commit comments