使用 React Native 打包器将文件作为字符串加载 [英] Loading a file as string with React Native packager

查看:31
本文介绍了使用 React Native 打包器将文件作为字符串加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

React Native Packager 是否可以将文本文件作为字符串加载?与 Webpack 的 Raw Loader 相同.

Is it possible with React Native Packager to load a text file as a string? As the same as Webpack's Raw Loader.

示例:

const someString = require('./something.txt');
console.log(someString);

实现这一目标最接近的方法是什么?

What is the closest way to achieve this?

推荐答案

你需要使用 React Native FS 模块,它在您的 React 代码中为您提供类似 FS 的命令:

You'll need to use the React Native FS module which gives you FS-like commands within your React code:

var RNFS = require('react-native-fs')
RNFS.readFile('./something.txt', 'utf8')
    .then((contents) => {
      console.warn(contents)
    })

这篇关于使用 React Native 打包器将文件作为字符串加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆