问题描述
我正在尝试在React Native中导入yaml文件。我在Metro defaults.js
文件中看到yaml已经被列为资产扩展。
import enYaml from '../i18n/locale/en.yaml';
解决方法
那是因为您将其作为资源加载。所以它是资源ID。您需要的是 What is the equivalent of a webpack loader when using the metro bundler in React Native?
的答案要在使用 Metro 使用的 babel.config.js 的 Expo 中执行此操作,您需要添加 babel-plugin-content-transformer
作为开发依赖项并按如下方式配置
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],plugins: [
[
'content-transformer',{
transformers: [
{
file: /\.ya?ml$/,format: 'yaml',},],...