aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/metro.config.cjs
diff options
context:
space:
mode:
authorxuatz <xzlow10@gmail.com>2025-08-16 23:28:00 +0900
committerGitHub <noreply@github.com>2025-08-16 17:28:00 +0300
commit17b59084c4a3345f127f45d3083254e060360bba (patch)
tree9da18cabc98e403b719298eed822650516488a93 /apps/mobile/metro.config.cjs
parent9059ca22312dec7878e398dd28a2fa18af560fc3 (diff)
downloadkarakeep-17b59084c4a3345f127f45d3083254e060360bba.tar.zst
fix(mobile): change to metro.config.cjs since migrating to type: module (#1845)
Diffstat (limited to 'apps/mobile/metro.config.cjs')
-rw-r--r--apps/mobile/metro.config.cjs57
1 files changed, 57 insertions, 0 deletions
diff --git a/apps/mobile/metro.config.cjs b/apps/mobile/metro.config.cjs
new file mode 100644
index 00000000..f9679cb2
--- /dev/null
+++ b/apps/mobile/metro.config.cjs
@@ -0,0 +1,57 @@
+// Learn more: https://docs.expo.dev/guides/monorepos/
+const { getDefaultConfig } = require("expo/metro-config");
+const { FileStore } = require("metro-cache");
+const { withNativeWind } = require("nativewind/metro");
+const path = require("path");
+
+module.exports = withTurborepoManagedCache(
+ withMonorepoPaths(
+ // eslint-disable-next-line no-undef
+ withNativeWind(getDefaultConfig(__dirname), {
+ input: "./globals.css",
+ configPath: "./tailwind.config.ts",
+ }),
+ ),
+);
+
+/**
+ * Add the monorepo paths to the Metro config.
+ * This allows Metro to resolve modules from the monorepo.
+ *
+ * @see https://docs.expo.dev/guides/monorepos/#modify-the-metro-config
+ * @param {import('expo/metro-config').MetroConfig} config
+ * @returns {import('expo/metro-config').MetroConfig}
+ */
+function withMonorepoPaths(config) {
+ // eslint-disable-next-line no-undef
+ const projectRoot = __dirname;
+ const workspaceRoot = path.resolve(projectRoot, "../..");
+
+ // #1 - Watch all files in the monorepo
+ config.watchFolders = [workspaceRoot];
+
+ // #2 - Resolve modules within the project's `node_modules` first, then all monorepo modules
+ config.resolver.nodeModulesPaths = [
+ path.resolve(projectRoot, "node_modules"),
+ path.resolve(workspaceRoot, "node_modules"),
+ ];
+
+ return config;
+}
+
+/**
+ * Move the Metro cache to the `node_modules/.cache/metro` folder.
+ * This repository configured Turborepo to use this cache location as well.
+ * If you have any environment variables, you can configure Turborepo to invalidate it when needed.
+ *
+ * @see https://turbo.build/repo/docs/reference/configuration#env
+ * @param {import('expo/metro-config').MetroConfig} config
+ * @returns {import('expo/metro-config').MetroConfig}
+ */
+function withTurborepoManagedCache(config) {
+ config.cacheStores = [
+ // eslint-disable-next-line no-undef
+ new FileStore({ root: path.join(__dirname, "node_modules/.cache/metro") }),
+ ];
+ return config;
+}