From 3472f8c56a248913511059f0252f14b469b2d266 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Thu, 30 Mar 2023 07:30:54 -0700 Subject: [PATCH] Bump RN CLI, add @react-native/metro-config to template (#36623) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36623 Changelog: [General][Changed] - The default `metro.config.js` in apps now extends `react-native/metro-config`, and should be updated in existing apps. ~~`react-native/rn-get-polyfills.js` is removed and should be updated to `react-native/js-polyfills` in existing apps (this is part of the new default config).~~ #publish-packages-to-npm ## Context ### React Native Metro config → React Native repo (https://github.com/facebook/react-native/pull/36502) We (the React Native team) are aiming to relocate the default Metro config for React Native out of `react-native-community/cli-plugin-metro` and **into the React Native repo + app template** as a new `react-native/metro-config` package. This is the first (and minimum viable) phase we can ship to separate the release process of Metro from RN CLI in order to reduce coupling and iterate faster for our users. **See full motivation, design, and test plan (which previewed the CLI bump) here: https://github.com/facebook/react-native/pull/36502** ## Changes NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after https://github.com/react-native-community/cli/pull/1875 is merged. - Upgrade `react-native-community/cli` to `11.0.0`, upgrade all `metro` packages to `0.76.0` (version distributed in this CLI release). - Update the `metro.config.js` file in `packages/react-native/template/`. - Now merges defaults from `react-native/metro-config`, and can be used with CLI >= 11.0.0. - Update the `metro.config.js` files for `packages/react-native/` and `packages/rn-tester/` (these are integration test locations). - Now merges defaults from `react-native/metro-config`, and can be used with CLI >= 11.0.0. Changes to `react-native/metro-config` — `0.72.1` (prepared but not depended on yet): - Export `mergeConfig` util (removing direct `metro-config` dependency in consuming projects). - Explicitly depend on `metro-react-native-babel-transformer` and `metro-runtime` (transitively included today). Reviewed By: cortinico, blakef Differential Revision: D44099691 fbshipit-source-id: 405635dd69fd50a1e9548279eaeda3c932b5b167 Original-Commit: https://github.com/facebook/react-native/commit/c5a47abaf894235f71eea03e57d2f5287d80f3d4 --- template/template/metro.config.js | 21 ++++++++------------- template/template/package.json | 17 ++++------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/template/template/metro.config.js b/template/template/metro.config.js index e91aba9..ff9cd36 100644 --- a/template/template/metro.config.js +++ b/template/template/metro.config.js @@ -1,17 +1,12 @@ +const {getDefaultConfig} = require('@react-native/metro-config'); +const {mergeConfig} = require('metro-config'); + /** - * Metro configuration for React Native - * https://github.com/facebook/react-native + * Metro configuration + * https://facebook.github.io/metro/docs/configuration * - * @format + * @type {import('metro-config').MetroConfig} */ +const config = {}; -module.exports = { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - }, -}; +module.exports = mergeConfig(getDefaultConfig(__dirname), config); diff --git a/template/template/package.json b/template/template/package.json index feaebd4..c0ba2cb 100644 --- a/template/template/package.json +++ b/template/template/package.json @@ -18,30 +18,21 @@ "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.12.5", "@react-native/eslint-config": "^0.72.1", + "@react-native/metro-config": "^0.72.0", "@tsconfig/react-native": "^2.0.2", + "@types/metro-config": "^0.76.1", "@types/react": "^18.0.24", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.2.1", "eslint": "^8.19.0", "jest": "^29.2.1", - "metro-react-native-babel-preset": "0.75.1", + "metro-config": "0.76.0", + "metro-react-native-babel-preset": "0.76.0", "prettier": "^2.4.1", "react-test-renderer": "18.2.0", "typescript": "4.8.4" }, "engines": { "node": ">=16" - }, - "overrides": { - "@react-native-community/cli": "11.0.0-alpha.0", - "@react-native-community/cli-platform-android": "11.0.0-alpha.0", - "@react-native-community/cli-platform-ios": "11.0.0-alpha.0", - "@react-native-community/cli-plugin-metro": "11.0.0-alpha.0" - }, - "resolutions": { - "@react-native-community/cli": "11.0.0-alpha.0", - "@react-native-community/cli-platform-android": "11.0.0-alpha.0", - "@react-native-community/cli-platform-ios": "11.0.0-alpha.0", - "@react-native-community/cli-plugin-metro": "11.0.0-alpha.0" } }