Home > OS >  Configure react-native-obfuscating-transformer and react-native-svg-transformer in metro.config.js
Configure react-native-obfuscating-transformer and react-native-svg-transformer in metro.config.js

Time:06-26

I want to use react-native-svg-transformer and react-native-obfuscating-transformer.but when configuring it using the merge config method time it works but when in some times it overwrites the react-native-svg-transformer in the metro.config file and react-native-svg-transformer started to not working .how can I resolve this.

using mergeConfig

const { getDefaultConfig, mergeConfig } = require("metro-config");

module.exports = (async () => {

  
  const {
    resolver: { sourceExts, assetExts },
  } = await getDefaultConfig();

  let config2 = {
    transformer: {
      babelTransformerPath: require.resolve("react-native-svg-transformer"),
    },
    resolver: {
      assetExts: assetExts.filter((ext) => ext !== "svg"),
      sourceExts: [...sourceExts, "svg"],
    },
  };

  let config1 = {
    transformer: {
      babelTransformerPath: require.resolve("./transformer"),
    },
  };

  



  return mergeConfig(config1, config2);
})();

and I tried using a custom transformer file .but I'm not sure about the syntax I wrote

var svgTransformer = require("react-native-svg-transformer");

module.exports.transform = function ({ src, filename, options }) {
  if (filename.endsWith(".svg")) {
    return svgTransformer.transform({ src, filename, options });
  } else {
    //return
    return require("./transformer");
  }
};

CodePudding user response:

I found an alternative for react-native-obfuscating-transformer.

obfuscator-io-metro-plugin

. this solved all the complex in my problem. check these links

https://www.npmtrends.com/@heroai/react-native-obfuscating-transformer-vs-obfuscator-io-metro-plugin-vs-react-native-obfuscating-transformer-clone-vs-react-native-obfuscator-vs-react-native-obscure

https://www.npmjs.com/package/obfuscator-io-metro-plugin

  • Related