Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ config.resolver.nodeModulesPaths = [
path.resolve(__dirname, "../node_modules"),
];

/**
* This is only required because this example app lives inside of the `react-native-css` repo.
*
* The root tsconfig maps `react-native-css/*` to `./src/*`, so Metro resolves
* `react-native-css/components` to `src/components/index.ts`, which exists only
* for types. Its `export * from "react-native"` compiles to `__esModule`
* getters, and Fast Refresh reads every one of them, including
* `PushNotificationIOS`, which throws on iOS. Load the runtime entry instead,
* as the package's `exports` map does for apps. Metro only tracks files whose
* extension is in `sourceExts`, so add `cts`; it's the only `.cts` file, and
* `ts` still wins when both match.
*/
config.resolver.sourceExts.push("cts");
const componentsTypesEntry = path.resolve(
__dirname,
"../src/components/index.ts",
);
const componentsEntry = path.resolve(__dirname, "../src/components/index.cts");
config.resolver.resolveRequest = (context, moduleName, platform) => {
const resolution = context.resolveRequest(context, moduleName, platform);
return resolution.type === "sourceFile" &&
resolution.filePath === componentsTypesEntry
? { type: "sourceFile", filePath: componentsEntry }
: resolution;
};

module.exports = withReactNativeCSS(config, {
globalClassNamePolyfill: true,
});
Loading