Struggling to incorporate react-native-svg-transformer into my metro.config.js setup

Looking to incorporate SVGs into my React Native app led me to consider using react-native-svg-transformer. However, I hit a roadblock when attempting to merge the GitHub metro.config.js with my local version due to significant differences in the configuration files. Struggling to navigate this merge without causing any issues, I would greatly appreciate any guidance on how to proceed. Below is the code snippet for react-native-svg-transform:

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

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

Here is a glimpse of my current metro.config.js:

"use strict";
function _asyncToGenerator(fn) {
  return function() {
    var gen = fn.apply(this, arguments);
    return new Promise(function(resolve, reject) {
      function step(key, arg) {
        try {
          var info = gen[key](arg);
          var value = info.value;
        } catch (error) {
          reject(error);
          return;
        }
        if (info.done) {
          resolve(value);
        } else {
          return Promise.resolve(value).then(
            function(value) {
              step("next", value);
            },
            function(err) {
              step("throw", err);
            }
          );
        }
      }
      return step("next");
    });
  };
}

const path = require("path");

const ROOT_PATH = path.resolve(__dirname, "basic_bundle");

module.exports = {
  cacheStores: [],
  maxWorkers: 1,
  projectRoot: ROOT_PATH,
  reporter: { update() {} },
  watchFolders: [path.resolve(__dirname, "../lib/polyfills")],
  server: { port: 10028 },
  resolver: {
    useWatchman: false
  },

  transformer: {
    assetRegistryPath: path.join(ROOT_PATH, "AssetRegistry"),
    babelTransformerPath: require.resolve("metro/src/reactNativeTransformer"),
    enableBabelRCLookup: false,
    enableBabelRuntime: false,
    getTransformOptions: (() => {
      var _ref = _asyncToGenerator(function*() {
        return {
          transform: { experimentalImportSupport: true, inlineRequires: false },
          preloadedModules: false,
          ramGroups: []
        };
      });
      return function getTransformOptions() {
        return _ref.apply(this, arguments);
      };
    })()
  }
};

If you have any suggestions for an easier method to handle this situation, please do share them as well. Furthermore, I am aware of the production issues plaguing react-native-svg-uri on Android and would like to avoid those altogether - can anyone confirm if the same concerns apply to react-native-svg-transform? Appreciate your insights!

Answer №1

Even though the documentation for Metro is lacking, I was able to figure it out for my project using the mergeConfig function.

Your script should have a structure similar to this:

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

// Rest of the script follows...

module.exports = mergeConfig(configA, configB);

I hope this information proves useful. Best of luck with your implementation!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling to correctly showcase my Firebase data in Angular using the orderByChild method

I have a user database structured like this : Database - Users - Id (generated using the push method) - email - firstName - ptsTotal - ... I am looking to create a ranking of users based on their total points (ptsTotal) in a game using ...

An in-depth guide on implementing debounce functionality for `keyup` events in Vue.js

I am attempting to detect when the user begins typing and stops typing using the debounce function. I experimented with Lodash and Underscore.js. On my textArea v-on:keyup="handler($event)" handler: function(e) { ...

Can a Javascript function be passed an endless array?

I'm curious if there's a way to generate an array that can be infinitely long. For example, if I have a function like `arr(2,3,4,5,6,7)`, is there a command that would allow me to treat those numbers as an array and automatically extend the table ...

Tips for safeguarding against the insertion of scripts into input fields

Is there a method to stop users from inputting scripts into text fields or text areas? function filter($event) { var regex = /[^a-zA-Z0-9_]/; let match = regex.exec($event.target.value); console.log(match); if (match) { $event.pre ...

Timeout reached during Protractor testing on an Angular webpage

I have developed a basic Angular portal page. The main feature is a search bar where users can enter the name of an NBA team like "Chicago Bulls", "Indiana Pacers", etc. Upon submitting the team name, users are directed to a second page where they can view ...

How can I deactivate a particular button in a React application?

Is there a way to selectively disable a button from a set of buttons that are generated from server data? I need to disable a specific button, even if there are many others, and also make it so that a button becomes permanently disabled once clicked. How ...

Nodejs is failing to write to the log file when running in a production environment

I have been working on recording HTTP requests to a .log file. This is how I create and write to it: const accessLogStream = fs.createWriteStream(path.join(__dirname, 'logger.log'), { flags: 'a' }); and then I write to it using middl ...

Creating iPhone style form elements using HTML

Thinking of replicating the form elements from iPhone using HTML/CSS but wondering if it already exists out there. I searched online but couldn't find anything. Has anyone come across something similar before? ...

Executing a python script from an html page by providing it with a string input

I've been searching everywhere for a solution to this problem, but I've only been able to find information on either the python side or the javascript side, and I really need both. Currently, I have a python script that I execute in the command ...

In what way can you set the sequence of properties in a JavaScript object for a MongoDB index while using node.js?

The MongoDB documentation emphasizes the importance of the sequence of fields in compound indexes. The definition of an object in ECMAScript states that it is an unordered collection of properties. When using MongoDB with node.js (such as with this mod ...

A method for automatically refreshing a webpage once it switches between specific resolutions

On my page www.redpeppermedia.in/tc24_beta/, it functions well at a resolution of over 980px. However, when the resolution is brought down to 768px, the CSS and media queries alter the layout. But upon refreshing the page at 768px, everything corrects itse ...

Using CSS to enhance the appearance of specific sections within my React JSX components

I'm currently working on a small React project where I'm mapping through an array of data to render its contents on the browser. However, I'm facing an issue regarding styling only certain parts of the rendered data and not all of them. The ...

Utilize the jQuery select() function to target and retrieve the elements within a specific div

Is there a way to utilize jQuery's .select() function to establish a selection range that covers all the content within a div? Within my div, I have a mix of labels, inputs, select elements, and various other UI components. I came across some code on ...

Having trouble with Silverlight running JavaScript?

When I try to call a JavaScript function from a SL component using the HtmlPage.Window.Invoke api, it works fine if the function is defined in the page (html). For example: HtmlPage.Window.Invoke("publishValue", topic, jsonObject); However, if I place th ...

Questions on how to utilize ES6 Express and static methods

Recently, I've been working with Express and wanted to incorporate ES6 using babel in my project. One question that has been on my mind is related to the use of static methods for handling requests, as shown below: class MyCtrl { static index (r ...

Submitting late leads to several consecutive submissions

I am working on a jQuery code that aims to introduce a short time delay to allow for the proper execution of an AJAX request: $('#form_id').submit(function(e) { e.preventDefault(); $submit_url = $(this).data('submitUrl'); ...

Can somebody please tell me the equivalent of the sleep() function in JavaScript?

Are there more efficient ways to implement a sleep function in JavaScript compared to the pausecomp function as shown below (sourced from here)? function pausecomp(millis) { var date = new Date(); var curDate = null; do { curDate = new Date(); ...

Instant urban locator

Is there a way to automatically populate the visitor's city in the membership form? Member Register Form Name: Emre Email:--- Pass:--- City: Istanbul // Automatically detected location How can I implement automatic location detection for the ...

Which HTML element does each script correspond to?

Are there any methods to identify the script used in certain HTML elements? For instance, if I wish to determine the script responsible for creating a drop-down menu, I can locate the HTML and CSS for the menu but not the JavaScript (or other scripts). I ...

Swap out one input for a newly generated input on the fly

Is there a way to replace a file input field with a text input field in jQuery while maintaining all properties such as id and name? Background: Currently, I have an <input type="file" name=".." id=".." /> being used for AJAX uploads. For Internet ...