@dva-rn/dotenv
v0.1.3
Published
react-native-config 对应的web版本,可以使用customize-cra
Downloads
1
Maintainers
Readme
@dva-rn/dotenv
对应 react-native-config
使用方式
yarn add @dva-rn/dotenv
create-react-app 使用 react-app-rewired
package.json
"scripts": {
"start": "DVA_RN_DOTENV_PATH=.env react-app-rewired start", // 使用 DVA_RN_DOTENV_PATH 指定环境变量参数
"build": "DVA_RN_DOTENV_PATH=.env-a react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},
config-overrides.js 文件
/*
* @Description: 重写CRA
* @Author: D__
* @Date: 2019-07-16 16:59:19
* @LastEditTime: 2019-08-20 12:49:28
*/
const {
override,
fixBabelImports,
addWebpackAlias,
babelInclude
} = require("customize-cra");
const { overrideDefinePlugin } = require("@dva-rn/dotenv/lib/dotenv");
const path = require('path');
module.exports = override(
overrideDefinePlugin(),
fixBabelImports("module-resolver", {
alias: {
"^react-native-config": "@dva-rn/dotenv"
}
}),
addWebpackAlias({
"react-native-config":"@dva-rn/dotenv"
}),
babelInclude([
path.resolve('src'), // make sure you link your own source
// any react-native modules you need babel to compile
path.resolve('../lib'),
]),
);
完整例子
https://github.com/dva-rn/dotenv/tree/master/packages/demo