J. Langer
J. Langer

Reputation: 330

Import specific javascript files as string in react-native with metro bundler

I appreciate your help!

Upvotes: 4

Views: 795

Answers (1)

J. Langer
J. Langer

Reputation: 330

In my case I needed to write a custom transformer.

const babelTransformer = require('metro-react-native-babel-transformer');

module.exports.transform = ({ src, filename, options }) => {
    return babelTransformer.transform({
      src: `let code = ${JSON.stringify(src)}; export default code;`,
      filename,
      options,
    });
};

Upvotes: 7

Related Questions