Gathering detailed insights and metrics for fe-config-loader
Gathering detailed insights and metrics for fe-config-loader
Gathering detailed insights and metrics for fe-config-loader
Gathering detailed insights and metrics for fe-config-loader
Load configuration dynamically at runtime for front end (vue or react) application
npm install fe-config-loader
Typescript
Module System
Node Version
NPM Version
63.2
Supply Chain
98.7
Quality
72.4
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
2,293
Last Day
1
Last Week
22
Last Month
42
Last Year
424
4 Stars
24 Commits
2 Forks
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
2.0.2
Package Id
fe-config-loader@2.0.2
Unpacked Size
10.22 kB
Size
4.37 kB
File Count
6
NPM Version
6.14.12
Node Version
10.24.1
Publised On
08 Aug 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
57.1%
22
Compared to previous week
Last month
180%
42
Compared to previous month
Last year
-59.8%
424
Compared to previous year
2
前端应用每次只在打包编译时加载一组环境变量,这给前端应用尤其是容器化部署造成了很大的不方便。本插件为前端应用提供了一种在运行时动态加载配置文件的方法,通过挂载config.json文件到容器内部并动态加载它,实现同一镜像部署到不同环境的需求。
目前已支持VUE应用和REACT应用。
简化获取配置方式,通过NODE_ENV自动判断获取配置内容的根节点
增加生产环境配置加密传输方式。注意: 加密配置传输,需要后台反向代理加密脚本,可以参考nginx配置方式实现方案
移除encrypt关键字
1npm install fe-config-loader
# .env.development文件
# 应用运行模式
NODE_ENV ='development'
############################### VUE ###################################
# 为VUE应用配置环境变量根键
# 非生产模式下有效,读取该根键下的配置变量
# 生产模式下,也就是'NODE_ENV = production'时该环境变量无效,读取根配置变量
# VUE_APP_CONFIG_ROOTKEY为空时,读取根配置变量
VUE_APP_CONFIG_ROOTKEY = "dev"
# 生产模式下,也就是'NODE_ENV = production'且反向代理将配置加密处理时
# 以下环境变量有效,配合设置反向代理加密配置,从1.1.0版本开始支持此功能
# 配置加密盐
VUE_APP_CONFIG_SALT = "tnP8DvkSp6MXtZHuP3ClhRTstakloIg"
# 配置加密迭代次数
VUE_APP_CONFIG_ITER = 16
# 配置加密偏移量
VUE_APP_CONFIG_IV = "PYYNphyM1GS1TXiJFKAtATSevEykrbL6eYh4J4FWEZUYSmdqP7e0Mn5xtXbrBgv8Ip"
#######################################################################
############################## REACT ##################################
# 为REACT应用配置环境变量根键
# 非生产模式下有效,读取该根键下的配置变量
# 生产模式下,也就是'NODE_ENV = production'时该环境变量无效,读取根配置变量
# REACT_APP_CONFIG_ROOTKEY为空时,读取根配置变量
REACT_APP_CONFIG_ROOTKEY = "dev"
# 生产模式下,也就是'NODE_ENV = production'且反向代理将配置加密处理时
# 以下环境变量有效,配合设置反向代理加密配置,从1.1.0版本开始支持此功能
# 配置加密盐
REACT_APP_CONFIG_SALT = "tnP8DvkSp6MXtZHuP3ClhRTstakloIg"
# 配置加密迭代次数
REACT_APP_CONFIG_ITER = 16
# 配置加密偏移量
REACT_APP_CONFIG_IV = "PYYNphyM1GS1TXiJFKAtATSevEykrbL6eYh4J4FWEZUYSmdqP7e0Mn5xtXbrBgv8Ip"
#######################################################################
...
1) 动态配置文件目录必须为:public/config.json
2) 支持单行注释// 和 多行注释/* ... */
1/* public/config.json */ 2{ 3 // 非生产模式下,XXX_APP_CONFIG_ROOTKEY = 'dev'时,读取以下配置信息 4 "dev": { 5 "baseUrl": "http://dev_hostname/api/v1", 6 "logLevel": "debug" 7 }, 8 // 非生产模式下,XXX_APP_CONFIG_ROOTKEY = 'sit'时,读取以下配置信息 9 "sit": { 10 "baseUrl": "http://sit_hostname/api/v1", 11 "logLevel": "info" 12 }, 13 // 生产模式或XXX_APP_CONFIG_ROOTKEY变量为空时,读取以下配置信息 14 "baseUrl": "http://prod_hostname/api/v1", 15 "logLevel": "error" 16}
1import axios from 'axios' 2import configLoader from 'fe-config-loader' 3 4const service = axios.create({ 5 baseURL: configLoader.get('baseUrl'), 6 timeout: 20000, 7 headers: { 8 'Content-Type': 'application/json; charset=utf-8' 9 } 10})
No vulnerabilities found.
No security vulnerabilities found.