Skip to content

Commit

Permalink
fix(metro): Add support for cjs extension in metro.config.js (#2689 by
Browse files Browse the repository at this point in the history
…@jamonholmgren)

* Add support for cjs extension in metro.config.js
* Add comments about inlineRequires and Reactotron
* Remove `experimentalInlineRequires` from metro config

[skip ci]
  • Loading branch information
jamonholmgren committed May 29, 2024
1 parent b4fc452 commit 7544fac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions boilerplate/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* if you're interested in adding screens and navigators.
*/
if (__DEV__) {
// Load Reactotron configuration in development. We don't want to
// include this in our production bundle, so we are using `if (__DEV__)`
// to only execute this in development.
// Load Reactotron in development only.
// Note that you must be using metro's `inlineRequires` for this to work.
// If you turn it off in metro.config.js, you'll have to manually import it.
require("./devtools/ReactotronConfig.ts")
}
import "./i18n"
Expand Down
10 changes: 9 additions & 1 deletion boilerplate/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ const config = getDefaultConfig(__dirname);

config.transformer.getTransformOptions = async () => ({
transform: {
experimentalImportSupport: false,
// Inline requires are very useful for deferring loading of large dependencies/components.
// For example, we use it in app.tsx to conditionally load Reactotron.
// However, this comes with some gotchas.
// Read more here: https://reactnative.dev/docs/optimizing-javascript-loading
// And here: https://github.com/expo/expo/issues/27279#issuecomment-1971610698
inlineRequires: true,
},
});

// This helps support certain popular third-party libraries
// such as Firebase that use the extension cjs.
config.resolver.sourceExts.push("cjs")

module.exports = config;

0 comments on commit 7544fac

Please sign in to comment.