I am looking to enable react-native-obfuscating-transformer but can't seem to get my code obfuscated.
I have the following in my metro.config.js
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
babelTransformerPath: require.resolve('./transformer'), // add here the transformer.js
},
I have the following in my transformer.js file:
const obfuscatingTransformer = require('react-native-obfuscating-transformer');
const typescriptTransformer = require('react-native-typescript-transformer');
const filter = (filename) => {
return filename.startsWith('src/path-to-file/index.tsx');
};
module.exports = obfuscatingTransformer({
// this configuration is based on https://github.com/javascript-obfuscator/javascript-obfuscator
obfuscatorOptions: {
compact: true,
controlFlowFlattening: false,
deadCodeInjection: false,
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
identifierNamesGenerator: 'hexadecimal',
log: false,
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
shuffleStringArray: true,
splitStrings: false,
stringArray: true,
stringArrayEncoding: false,
stringArrayThreshold: 0.75,
unicodeEscapeSequence: false,
},
upstreamTransformer: typescriptTransformer,
emitObfuscatedFiles: true,
enableInDevelopment: true,
filter: filter,
trace: true,
});
However when I build my app (I am testing via yarn start) I can see that my files are "obfuscated"
transform[stdout]: Obfuscating src/path-to-file/index.tsx
However comparing the normal file vs it's .obfuscated. counterpart shows nothing has been obfuscated.
Normal file:
const myApiKey = 'foo';
Obfuscated file:
var myApiKey = 'foo';
Any help would be largely appreciated.
Edit: I have opted for obfuscator-io-metro-plugin which has successfully obfuscated my code.