首页 > 解决方案 > 为 react-native-config 配置声明模块?

问题描述

我有一个旧的项目配置环境,react-native-dotenv就像 beblow

declare module 'react-native-dotenv' {
  export const APP_ROOT_API: string;
  export const APP_PUBLIC_AVATAR_PATH: string;
  export const APP_ABOUT_URL: string;
  export const APP_ONESIGNAL_APP_ID: string;
  export const APP_ONESIGNAL_PREFIX: string;
  export const APP_TEST_USER_ID: string;
  export const APP_TEST_TOKEN: string;
  export const APP_TEST_REFRESH_TOKEN: string;
  export const CLIENT_ID: string;
  export const CLIENT_SECRET: string;
  export const REDIRECT_URL: string;
  export const AUTHORIZATION_ENDPOINT: string;
  export const TOKEN_ENDPOINT: string;
  export const SCOPES;
  export const ENV;
}

但是现在我想通过使用来更改配置环境react-native-config

我可以像这样更改代码吗:

declare module 'react-native-config' {
  export const APP_ROOT_API: string;
  export const APP_PUBLIC_AVATAR_PATH: string;
  export const APP_ABOUT_URL: string;
  export const APP_ONESIGNAL_APP_ID: string;
  export const APP_ONESIGNAL_PREFIX: string;
  export const APP_TEST_USER_ID: string;
  export const APP_TEST_TOKEN: string;
  export const APP_TEST_REFRESH_TOKEN: string;
  export const CLIENT_ID: string;
  export const CLIENT_SECRET: string;
  export const REDIRECT_URL: string;
  export const AUTHORIZATION_ENDPOINT: string;
  export const TOKEN_ENDPOINT: string;
  export const SCOPES;
  export const ENV;
}

标签: typescriptreact-native

解决方案


native-dotenv maintainer here.react-native-config` 需要更多的时间来设置链接和其他东西。这些也是来自 .env 文件吗?


推荐阅读