What is @react-native-community/cli-plugin-metro?
The @react-native-community/cli-plugin-metro package is a plugin for the React Native CLI that integrates Metro, the JavaScript bundler for React Native. This plugin facilitates the configuration and customization of Metro for React Native projects, enhancing the development experience by providing tools for optimizing and managing the bundling process.
What are @react-native-community/cli-plugin-metro's main functionalities?
Custom Metro Configuration
Allows developers to customize the Metro configuration specific to their React Native project needs, such as defining file extensions, blacklisting files, and setting transformer options.
module.exports = {
resolver: {
sourceExts: ['jsx', 'js', 'ts', 'tsx', 'json'],
blacklistRE: blacklist([/ignore_files\/.*$/])
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
serializer: {
getPolyfills: () => [require.resolve('react-native/Libraries/polyfills/console.js')]
}
};
Optimizing Bundling
Enhances the performance of the JavaScript bundling process by allowing developers to define optimization settings such as minification and mangling to improve load times and application performance.
const { makeMetroConfig } = require('@react-native-community/cli-plugin-metro');
const config = makeMetroConfig({
projectRoot: __dirname + '/src',
watchFolders: [__dirname + '/node_modules'],
transformer: {
minifierConfig: {
mangle: true,
keep_classnames: true,
keep_fnames: true,
output: {
ascii_only: true,
quote_style: 3,
wrap_iife: true
}
}
}
});
Other packages similar to @react-native-community/cli-plugin-metro
metro-react-native-babel-preset
This package provides a set of Babel presets configured for React Native applications using Metro. It is similar to @react-native-community/cli-plugin-metro in that it helps in setting up the project's Babel configuration for optimal performance with Metro, but it focuses more on the Babel presets rather than the broader Metro configuration.
haul
Haul is a drop-in replacement for Metro bundler built on webpack, offering a similar feature set with additional customization options that webpack provides. It compares to @react-native-community/cli-plugin-metro by offering an alternative bundling solution with potentially more familiar configuration options for developers experienced with webpack.
[Removed]
This package is now relocated as @react-native/community-cli-plugin
.
To make new contributions to this package, please open a PR in the React Native repo (contributing guide).