1.0.14 • Published 2 months ago

@jswork/env-manager v1.0.14

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

env-manager

Environment manager for frontend.

version license size download

installation

npm install @jswork/env-manager

usage

import EnvManager from '@jswork/env-manager';

// vite
const viteEnv = new EnvManager({
  prefix: 'VITE_',
  env: import.meta.env
});

// webpack
const craEnv = new EnvManager({
  prefix: 'REACT_APP_',
  env: process.env
});

You can use env-cmd to manage your envs.

// ---------- package.json
"scripts": {
  "start": "env-cmd -e local react-scripts start",
  "build:beta": "env-cmd -e beta react-scripts build",
  "build:prod": "env-cmd -e prod react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject"
}

You can use env-cmdrc.js to manage your envs.

// ---------- .env-cmdrc.js
module.exports = craEnv.set({
  "local": {
    "API_URL": "http://localhost:3000",
    "BUILD_ENV": 'local-api.github.com/users/afeiship',
  },
  "beta": {
    "API_URL": "http://beta.api.com",
    "BUILD_ENV": 'beta-api.github.com/users/afeiship',
  },
  "production": {
    "API_URL": "http://api.com",
    "BUILD_ENV": 'api.github.com/users/afeiship',
  },
});

// ---------- src/app.tsx // get 'BUILD_ENV' const buildEnv = craEnv.get('BUILD_ENV'); // get all const envs = craEnv.get();

## types
```ts
// add to global.d.ts OR nx-env.d.ts
/// <reference types="@jswork/env-manager/dist/@types" />

license

Code released under the MIT license.

1.0.14

2 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago