import { name } from '../../package.json' /** * 如无必要,请不要 import 这个文件 * 在组件中使用 `this.$config` 访问 * 例如 `this.$config.name` / `this.$config.apiURL` */ class Config { /** * 应用名称 */ public readonly name = this.get('NAME') /** * 请求的接口地址,整个应用,只有一个地址 */ public readonly apiURL = this.get('SERVER_URL').replace(/\/$/, '') /** * public 目录地址 */ public readonly publicPath = process.env.BASE_URL /** * 读取package.json名称 */ public readonly pkgName = name /** * 从环境变量中获取配置, 已不推荐使用 * 需要获取配置,写在 Config 这里类里面 * @param key */ private get(key: string): string { return process.env[`VUE_APP_${key}`] || '' } } const config = new Config() export default config export { Config }