Skip to content

Commit

Permalink
Update app template's metro config with latest upstream changes (#12279)
Browse files Browse the repository at this point in the history
## Description

This PR applies the changes we need to an app's metro config on top of a more recent snap of the default metro config for an RN app.

### Type of Change
- Bug fix (non-breaking change which fixes an issue)
- Breaking change (fix or feature that would cause existing functionality to not work as expected)
- 
### Why
To fix new apps not loading because of a badly configured bundle.

Resolves: #12268

### What
Coped the current RN template metro.config.js and applied our changes.

## Screenshots
N/A

## Testing
Verified a new app loads correctly

## Changelog
Should this change be included in the release notes: yes

Update app template's metro config with latest upstream changes
  • Loading branch information
jonthysell committed Oct 21, 2023
1 parent 0b31812 commit 68094c0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Update app template's metro config with latest upstream changes",
"packageName": "react-native-windows",
"email": "jthysell@microsoft.com",
"dependentChangeType": "patch"
}
19 changes: 12 additions & 7 deletions vnext/template/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');

const fs = require('fs');
const path = require('path');
const exclusionList = require('metro-config/src/defaults/exclusionList');
Expand All @@ -12,7 +8,14 @@ const rnwPath = fs.realpathSync(
path.resolve(require.resolve('react-native-windows/package.json'), '..'),
);

module.exports = {
/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
* @type {import('metro-config').MetroConfig}
*/

const config = {
resolver: {
blockList: exclusionList([
// This stops "react-native run-windows" from causing the metro server to crash if its already running
Expand All @@ -36,3 +39,5 @@ module.exports = {
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
},
};

module.exports = mergeConfig(getDefaultConfig(__dirname), config);
21 changes: 14 additions & 7 deletions vnext/template/metro.devMode.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');

const fs = require('fs');
const path = require('path');
const exclusionList = require('metro-config/src/defaults/exclusionList');
Expand All @@ -17,7 +13,14 @@ const rnwRootNodeModules = path.resolve(rnwPath, '..', 'node_modules');
const rnwPackages = path.resolve(rnwPath, '..', 'packages');
// devMode]

module.exports = {
/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
* @type {import('metro-config').MetroConfig}
*/

const config = {
// [devMode
watchFolders: [rnwPath, rnwRootNodeModules, rnwPackages],
// devMode]
Expand Down Expand Up @@ -45,5 +48,9 @@ module.exports = {
inlineRequires: true,
},
}),
// This fixes the 'missing-asset-registry-path` error (see https://github.com/microsoft/react-native-windows/issues/11437)
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
},
};

module.exports = mergeConfig(getDefaultConfig(__dirname), config);
19 changes: 12 additions & 7 deletions vnext/templates/cpp-app/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');

const fs = require('fs');
const path = require('path');
const exclusionList = require('metro-config/src/defaults/exclusionList');
Expand All @@ -17,7 +13,14 @@ const rnwRootNodeModules = path.resolve(rnwPath, '..', 'node_modules');
const rnwPackages = path.resolve(rnwPath, '..', 'packages');
// devMode]{{/devMode}}

module.exports = {
/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
* @type {import('metro-config').MetroConfig}
*/

const config = {
//{{#devMode}} [devMode
watchFolders: [rnwPath, rnwRootNodeModules, rnwPackages],
// devMode]{{/devMode}}
Expand Down Expand Up @@ -49,3 +52,5 @@ module.exports = {
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
},
};

module.exports = mergeConfig(getDefaultConfig(__dirname), config);

0 comments on commit 68094c0

Please sign in to comment.