How to install react-native-svg-transformer without Expo?

Viewed 525

I've a react-native 0.64.2 project without Expo. Using this instruction doesn't work for me, because I don't have the package metro-config which means I can't import getDefaultConfig.

metro.config.js

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

module.exports = (async () => {
  const {
    resolver: { sourceExts, assetExts }
  } = await getDefaultConfig();
  return {
    transformer: {
      babelTransformerPath: require.resolve("react-native-svg-transformer")
    },
    resolver: {
      assetExts: assetExts.filter(ext => ext !== "svg"),
      sourceExts: [...sourceExts, "svg"]
    }
  };
})();

Any idea? Thanks in advance!

1 Answers

Metro != Expo. It is a bundler used to transform and combine both JavaScript and all the related assets - similar to webpack, but for RN applications.

If you're using @react-native-community/cli package, it has both metro and metro-config as its dependencies, so you should be able to require this package.

Related