1.3.6 • Published 5 months ago

ambiences v1.3.6

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

多环境 webpck\vite plugins 配置生成当前环境配置(解决多余 IP 暴露引起的安全性问 题)。

Install

$ npm install -D ambiences
// or
$ yarn add -D ambiences

Usage

Via .ambiences (Recommended)

  1. [[XXX]] 环境名称,与 package.jsonscripts --mode NODE_ENV 匹配
  2. [xxx] 配置名字,后期系统中调用需要。
  3. xxx=xxx 详细配置

多个环境配置的情况下,这个格式不断重复调整环境参数。

在非build 或者 NODE_ENV=production 并且 outDir 不为空的情况下都会在 outDir 目录下创建对应配置文件可作为外部引入文件处理。

.ambiences

[[dev]] // 环境配置名称
[api] // 参数名称
requestURL = "xxx.xxx.test"
[config] // 参数名称
systemName = "DevTest"
requestURL = "xxx.pro.test"

[[production]]
[api]
requestURL = "xxx.pro.test"
[config]
// 系统名称
qasd = "系统名称"
systemName = "Test";
iiii = 123123
arr = [1,2,3,4,5,6,7,8]
obj = {a:1,b:2,c:3}
isTre = true

package.json

{
	……
	"scripts": {
		"dev": "node ./index.js --mode NODE_ENV=dev",
		"test": "node ./index.js --mode NODE_ENV=test",
		"production": "node ./index.js --mode NODE_ENV=production",
	}
	……
}

ambiences(type?: string,outDir?: string,dev?: DevConfig)

Parameter

参数名称类型描述是否必填默认参数备选参数
typestring打包后需要处理成什么格式的ambiences.config.*-jsonjson/js
outDirstring打包后ambiences.config.*输出到什么位置-dist-
devDevConfig开发环境配置-defineDevConfig-

defineDevConfig:DevConfig

参数名称类型描述是否必填默认参数备选参数
envstring开发环境需要什么amb.*类型文件-jsjsx/js/ts/tsx
pathstring开发环境中配置文件输出到什么目录-src-
isProboolen当前是否为生产版本-false-

Plugins Use

import ambiences from 'ambiences';
module.exports = {
	……
	"plugins": [
		ambiences('js', "dist")
	],
	……
}

// or

import {ambiences,DevConfig} from 'ambiences';
const ambiencesDevConfig:DevConfig = {
	// 项目目录
	inputDir: '',
	// 开发环境需要什么amb.*类型文件,可选 ts、tsx、js、jsx
    env: "js",
    // 开发环境中配置文件输出到什么目录
    path: "src/config",
    // 当前是否为生产版本
    isPro: false
}
module.exports = {
	……
	"plugins": [
		ambiences('js', "dist",ambiencesDevConfig)
	],
	……
}

ambiences production

|--dist
	|-- ……
	|-- ambiences.config.js
	|-- ……

production 环境为例

ambiences.config.js
var ambiences = {
	ENV: 'production',
	api: {
		requestURL: 'http://xxx.api.pro.com',
	},
	config: {
		systemName: 'Production system name',
	},
};
ambiences.config.json
{
	"ENV": "production",
	"api": {
		"requestURL": "http://xxx.api.pro.com"
	},
	"config": {
		"systemName": "Production system name"
	}
}

ambiences development

|--src
	|-- ……
	|-- ambiences.config.js
	|-- ……

dev 环境为例

ambiences.config.js
export const ENV = 'dev';
export const api = {
	requestURL: 'http://xxx.api.dev.com',
};
export const config = {
	systemName: 'DevDependencies system name',
};

export default { api, config, ENV };

问题反馈

在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流

1.3.6

5 months ago

1.3.5

5 months ago

1.3.3

5 months ago

1.3.2

5 months ago

1.3.1

5 months ago

1.3.0

5 months ago

1.2.35

5 months ago

1.2.38

5 months ago

1.2.39

5 months ago

1.2.36

5 months ago

1.2.37

5 months ago

1.2.27

5 months ago

1.2.28

5 months ago

1.2.29

5 months ago

1.2.30

5 months ago

1.2.31

5 months ago

1.2.32

5 months ago

1.2.33

5 months ago

1.2.26

1 year ago

1.2.23

1 year ago

1.2.24

1 year ago

1.2.22

1 year ago

1.2.25

1 year ago

1.2.18

2 years ago

1.2.19

2 years ago

1.2.20

2 years ago

1.2.21

2 years ago

1.2.12

2 years ago

1.2.13

2 years ago

1.2.16

2 years ago

1.2.17

2 years ago

1.2.15

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.9

2 years ago

1.2.11

2 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.2.1

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago