简体   繁体   中英

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

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");
  }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM