metro-plugin-duplicates-checker
@rnx-kit/metro-plugin-duplicates-checker
checks for duplicate packages in your
bundle.
Usage
There are several ways to use this package.
The recommended way is to add it as a plugin in your metro.config.js
using
@rnx-kit/metro-serializer
:
const { makeMetroConfig } = require("@rnx-kit/metro-config");
+const {
+ DuplicateDependencies,
+} = require("@rnx-kit/metro-plugin-duplicates-checker");
+const { MetroSerializer } = require("@rnx-kit/metro-serializer");
module.exports = makeMetroConfig({
serializer: {
+ customSerializer: MetroSerializer([DuplicateDependencies()]),
},
});
You can also check for duplicate packages after a bundle is created:
const {
checkForDuplicatePackagesInFile,
} = require("@rnx-kit/metro-plugin-duplicates-checker");
checkForDuplicatePackagesInFile(pathToSourceMapFile, {
ignoredModules: [],
bannedModules: [],
});
If you have a source map object, you can pass that directly to
checkForDuplicatePackages()
:
const {
checkForDuplicatePackages,
} = require("@rnx-kit/metro-plugin-duplicates-checker");
checkForDuplicatePackages(mySourceMap, {
ignoredModules: [],
bannedModules: [],
});
Options
Key | Type | Default | Description |
---|---|---|---|
bannedModules | string[] | [] | List of modules that are banned. |
ignoredModules | string[] | [] | List of modules that can be ignored. |
throwOnError | boolean | true | Whether to throw when duplicates are found. |