Metro Plugin
A Metro plugin which hooks into the bundling process to protect the output bundle. The plugin can be configured to process only the modules that are "first-party" application code, or to process the whole bundle, including the third-party modules and the React Native related bootstrapping code.
Supported Versions and Bundle Formats
Supported React Native versions: >=0.59.0
Supported bundle formats: Plain bundle
Note: Support for the Indexed RAM bundle and File RAM bundle could be expected in a future release.
Installation
Install the plugin to your project:
npm install <package-directory>/preemptive-pjsd-core-{version}.tgz <package-directory>/preemptive-pjsd-metro-plugin-{version}.tgz --save-dev
OR
yarn add file:<package-directory>/preemptive-pjsd-core-{version}.tgz file:<package-directory>/preemptive-pjsd-metro-plugin-{version}.tgz
Note: The plugin has
@preemptive/pjsd-core
as its peerDependency this is why you must also install it.
Usage
Add the plugin to your metro.config.js
:
const pjsdMetroPlugin = require("@preemptive/pjsd-metro-plugin")(
// --PJSD configuration
{
configurationFile: "pjsd.config.json", // Path to the configuration file if any or you could put your configuration directly here
quietMode: false, // Display protection logs
protectUserModulesOnly: false, // If false the whole bundle will be protected, otherwise only the "first-party" application code
/* Other PJSD options e.g. booleanLiterals, stringLiterals etc. could also be provided here */
},
// --Metro configuration
{
resolver: {
/* resolver Metro options */
},
transformer: {
/* transformer Metro options */
},
serializer: {
/* serializer Metro options */
},
server: {
/* server Metro options */
}
/* general Metro options */
}
)
module.exports = pjsdMetroPlugin;
Configuration
The PJSD Metro plugin accepts the same configuration object as the PJSD configuration file. You can learn more about it at the documentation home. As you can see, you can also specify your own Metro options and they will be applied.
Note: If a PJSD
configurationFile
is present, its individual configuration lines overwrite the PJSD configuration directly used in themetro.config.js
. E.g. if you setbooleanLiterals: true
for thepjsdMetroPlugin
but there is aconfigurationFile
set which hasbooleanLiterals: false
, then the latter will take precedence.