Skip to content

Commit

Permalink
chore: setup expo example for bob
Browse files Browse the repository at this point in the history
  • Loading branch information
KiwiKilian committed Nov 22, 2024
1 parent 8f3316c commit cd62660
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
17 changes: 14 additions & 3 deletions packages/expo-app/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
module.exports = {
presets: ["babel-preset-expo"],
};
/* eslint-env node */
const path = require("path");
const { getConfig } = require("react-native-builder-bob/babel-config");

const pkg = require("../../package.json");

const root = path.resolve(__dirname, "..", "..");

module.exports = getConfig(
{
presets: ["babel-preset-expo"],
},
{ root, pkg },
);
35 changes: 28 additions & 7 deletions packages/expo-app/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
/* eslint-env node */
const { getDefaultConfig } = require("expo/metro-config");
const path = require("path");
const { getConfig } = require("react-native-builder-bob/metro-config");

const projectRoot = __dirname;
const workspaceRoot = path.resolve(projectRoot, "../..");
const pkg = require("../../package.json");

const project = __dirname;
const root = path.resolve(project, "..", "..");

/**
* @param config {import('expo/metro-config').MetroConfig}
* @returns {import('expo/metro-config').MetroConfig}
*/
function withMonorepoPaths(config) {
// Watch all files in the monorepo
config.watchFolders = [workspaceRoot];
config.watchFolders = [root];

// Set `node_modules` to resolve
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, "node_modules"),
path.resolve(workspaceRoot, "packages/examples/node_modules"),
path.resolve(workspaceRoot, "node_modules"),
path.resolve(project, "node_modules"),
path.resolve(root, "packages/examples/node_modules"),
path.resolve(root, "node_modules"),
];

// Resolve only (sub)dependencies from the `nodeModulesPaths`
config.resolver.disableHierarchicalLookup = true;

// Use src instead of lib
config.resolver.resolveRequest = (context, moduleName, platform) => {
if (moduleName.startsWith(pkg.name)) {
return {
filePath: path.resolve(__dirname, "..", "..", "src", "index.ts"),
type: "sourceFile",
};
}

return context.resolveRequest(context, moduleName, platform);
};

return config;
}

module.exports = withMonorepoPaths(getDefaultConfig(projectRoot));
module.exports = withMonorepoPaths(
getConfig(getDefaultConfig(project), {
root,
pkg,
project,
}),
);
19 changes: 10 additions & 9 deletions packages/react-native-app/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@ const { getDefaultConfig } = require("@react-native/metro-config");
const path = require("path");
const { getConfig } = require("react-native-builder-bob/metro-config");

const root = path.resolve(__dirname, "..", "..");
const projectRoot = __dirname;
const workspaceRoot = path.resolve(projectRoot, "../..");
const pkg = require("../../package.json");

const project = __dirname;
const root = path.resolve(project, "..", "..");

/**
* @param config {import('metro-config').MetroConfig}
* @returns {import('expo/metro-config').MetroConfig}
*/
function withMonorepoPaths(config) {
// Watch all files in the monorepo
config.watchFolders = [workspaceRoot];
config.watchFolders = [root];

// Set `node_modules` to resolve
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, "node_modules"),
path.resolve(workspaceRoot, "packages/examples/node_modules"),
path.resolve(workspaceRoot, "node_modules"),
path.resolve(project, "node_modules"),
path.resolve(root, "packages/examples/node_modules"),
path.resolve(root, "node_modules"),
];

// Resolve only (sub)dependencies from the `nodeModulesPaths`
config.resolver.disableHierarchicalLookup = true;

// Use src instead of lib
config.resolver.resolveRequest = (context, moduleName, platform) => {
if (moduleName.startsWith(pkg.name)) {
return {
Expand All @@ -41,9 +42,9 @@ function withMonorepoPaths(config) {
}

module.exports = withMonorepoPaths(
getConfig(getDefaultConfig(projectRoot), {
getConfig(getDefaultConfig(project), {
root,
pkg,
project: __dirname,
project,
}),
);

0 comments on commit cd62660

Please sign in to comment.