-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support react-native builds #2541
Comments
Field notes on metro bundlerIt doesn't seem to matter much if you run This is (roughly) how you call the bundler: npm_package_bin(
name = "metro",
outs = ["index.android.js"],
args = [
"bundle",
"--entry-file",
"./src/mobile/index.js", # must be relative to the WORKSPACE
"--platform",
"android",
"--dev",
"true",
"--bundle-output",
"$@",
"--config",
"./metro.config.js", # the config must be next to the WORKSPACE
],
data = glob([
# pass in all the sources you want metro to handle. At the very least you need to pass in the index.js
# (which can then reference from your ts_projects)
"*/**",
]) + [
# pass in top-level configuration. Many things RN cares about are resolved against the top-level package.json
"//:package.json", # react-native needs to see the package.json or it will run in the detached mode
"//:metro.config.js", # needs to be at the WORKSPACE
"//:tsconfig.json",
] + [
"@npm//metro-react-native-babel-preset",
"@npm//:node_modules",
] + [
# you can pass in all your ts_project deps as usual
"//src/test",
],
package = "react-native",
package_bin = "react-native",
) Here's a sample metro config: const metroResolver = require('metro-resolver');
const path = require('path');
const rootDirs = [
".",
"./bazel-out/darwin-fastbuild/bin",
"./bazel-out/k8-fastbuild/bin",
"./bazel-out/x64_windows-fastbuild/bin",
"./bazel-out/darwin-dbg/bin",
"./bazel-out/k8-dbg/bin",
"./bazel-out/x64_windows-dbg/bin",
];
module.exports = {
// projectRoot: '', // TODO: do we actually need this?
resolver: {
resolveRequest: (_context, realModuleName, platform, moduleName) => {
console.log(`[BAZEL] Resolving: ${moduleName}`);
const { resolveRequest, ...context } = _context;
try {
return metroResolver.resolve(context, moduleName, platform);
} catch (e) {
console.log(`[BAZEL] Unable to resolve with default Metro resolver: ${moduleName}`);
}
try {
const absOriginalModuleDir = path.dirname(_context.originModulePath);
const relOriginalModuleDir = absOriginalModuleDir.replace(__dirname, './');
// NB: it seems that the above ./ doesn't work while the below does, because
// path.join actually eats it up and simplifies the path. require.resolve()
// needs it though, to do the "local" resolution.
const relPath = './' + path.join(relOriginalModuleDir, realModuleName);
console.log(`[BAZEL] Resolving manually: ${relPath}`);
console.log(`[BAZEL] absOriginalModuleDir=${absOriginalModuleDir})`);
console.log(`[BAZEL] relOriginalModuleDir=${relOriginalModuleDir})`);
// NB: we only care about .js files from in here as tsc would have processed them anyways
const match = require.resolve(relPath, { paths: rootDirs });
return {
type: 'sourceFile',
filePath: match,
};
} catch (e) {
console.log(`[BAZEL] Unable to resolve with require.resolve: ${moduleName}`);
}
},
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
}; |
Field notes on androidYou need to have module.exports = {
project: {
android: {
sourceDir: './src/mobile/android',
},
},
}; This can be verified via
It isn't possible to skip gradle completely as it does some codegen. FB seems to use buck at some point of their pipeline but they still wrap it all up in gradle. |
This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs! |
Hey Stalebot! This is definitely an important issue. This issue is a blocker for me getting into Bazel, as I was looking at it to improve our reproducibility / performance when building a monorepo with multiple react-native apps. I don't have the active knowledge of how bazel works to implement my own workarounds, and since I'm preparing this project for a team of react-native developers (who also don't know bazel), we don't have the knowledge or spare bandwidth to contribute, and I wouldn't want to ramp up a team to rely on a tool if it's not a primary supported use-case. Hope that's sufficient justification to continue! |
A quick update: I'm still on it. I'm trying to teach bazel to run android builds, so far unsuccessful. It works with an external Makefile but I consider that a sub-optimal solution. |
Minor comment: The bundling doesn't seem to work with older react and react-native versions. Had to update from |
This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs! |
Ping. Such support is really important and would be nice to be part of rules_nodejs. |
in our 5.0 we are working to reduce scope of rules_nodejs. Maybe someone would like to own a rules_react_native (or maybe it could go with a rules_react) @farcaller do you still hope to come back to it? |
Unfortunately I couldn't make it work any reliably and somewhat gave up. I'm ok to close this given the reduced scope. |
So I know this is closed, but I think maybe we might re-open it until we find out what a suitable home for this issue is? any thoughts @alexeagle ? FWIW I just launched this MNF discussion on the same topic and would love to get some input from folks: MobileNativeFoundation/discussions#145 |
@farcaller @mgenov -- we are considering assembling a working group to collaborate on this as there is interest from a few folks in the community in making this happen. if you have any interest in collaborating in this work and/or your organization has the capability to fund it, please let me know; whether in the MNF discussion item or directly in Bazel slack or flare.build's inbox. looks like this will likely end up in a separate repo, which is fine by me, but we'll at least keep this issue updated as that progresses, since this is currently where folks are likely to land first. |
This issue has been automatically marked as stale because it has not had any activity for 6 months. It will be closed if no further activity occurs in 30 days. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs! |
Until this feature is added, I unfortunately can't really use bazel, but I hope this comment is enough to tell stale-bot not to close this ticket! |
This issue has been automatically marked as stale because it has not had any activity for 6 months. It will be closed if no further activity occurs in 30 days. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs! |
This is still requested. Cannot use bazel for mobile react-native without this! Thanks! |
This issue has been automatically marked as stale because it has not had any activity for 6 months. It will be closed if no further activity occurs in 30 days. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs! |
This issue was automatically closed because it went 30 days without any activity since it was labeled "Can Close?" |
🚀 feature request
This is a fork off the #2411 now that I am confident that rn support is possible to a reasonable extent. I want to collect the work on the matter in a more structured way than comments on a PR that says it's not possible :)
Relevant Rules
I expect we will need something akin to a
rollup_bundle
, probablymetro_bundle
to incapsulate the complexity of bundling the RN code.Description
I want to see bazel building react-native projects end to end, delivering an appropriate apk or ipa for the mobile device. Good developer story (i.e. fast reloads and HMR) are useful but aren't subject of the initial effort.
Describe the solution you'd like
There are at least 3 parts to building a RN project:
Describe alternatives you've considered
We could focus on bundling the JS code alone and ignore the native host apps which can be built using gradle & xcodebuild as appropriate.
Feasible milestones
ts_project
rules for any supporting code;metro_bundle
rule;The text was updated successfully, but these errors were encountered: