babel-plugin-env-val
v1.0.2
Published
babel 环境变量替换插件
Downloads
34
Maintainers
Readme
babel-plugin-env-val
babel 环境变量替换插件
插件功能
环境变量替换为常量值
引入插件
npm install babel-plugin-env-val --save-dev
插件配置
// babel.config.js
module.exports = {
presets: [
// other presets
],
plugins: [
[
"babel-plugin-env-val",
{
...process.env,
MY_ENV_NUMBER: 111,
MY_ENV_STRING: "string",
MY_ENV_FUNC: (value) => {
return "MY_ENV_FUNC" + value;
},
},
],
],
};
使用
根据以上配置插件执行结果如下
// 输入内容
process.env.MY_ENV_NUMBER;
// 输出内容
111;
// 输入内容
process.env.MY_ENV_FUNC("_222");
// 输出内容
"MY_ENV_FUNC_222";