{"id":18055754,"url":"https://github.com/marinerer/gulp-env-loader","last_synced_at":"2025-04-05T09:24:29.252Z","repository":{"id":154228596,"uuid":"631984201","full_name":"Marinerer/gulp-env-loader","owner":"Marinerer","description":"A gulp plugin for loading environment variables and replacing them in the contents of files. 👉  处理环境变量的 gulp 插件,用于加载环境变量配置文件并替换内容。","archived":false,"fork":false,"pushed_at":"2023-10-26T01:07:26.000Z","size":74,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T06:48:31.695Z","etag":null,"topics":["dotenv","env","env-loader","gul-env-loader","gulp-env","gulp-environment","gulp-plugin"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/gulp-env-loader","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Marinerer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-24T13:23:07.000Z","updated_at":"2023-10-25T12:02:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"e4820555-aa0b-4589-b52b-b0d668aee39e","html_url":"https://github.com/Marinerer/gulp-env-loader","commit_stats":null,"previous_names":["marinerer/gulp-env-loader","meqn/gulp-env-loader"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marinerer%2Fgulp-env-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marinerer%2Fgulp-env-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marinerer%2Fgulp-env-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marinerer%2Fgulp-env-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Marinerer","download_url":"https://codeload.github.com/Marinerer/gulp-env-loader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247313934,"owners_count":20918719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotenv","env","env-loader","gul-env-loader","gulp-env","gulp-environment","gulp-plugin"],"created_at":"2024-10-31T01:11:50.997Z","updated_at":"2025-04-05T09:24:29.217Z","avatar_url":"https://github.com/Marinerer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-env-loader\n\n[ [English](./README.md) | [中文](./README.zh_CN.md) ]\n\nA gulp plugin for loading environment variables and replacing them in file contents.  \nIt can load environment variables from a specified configuration file or from the default `.env` file.\n\nIt uses `dotenv` to load additional environment variables from the following files in your environment directory, and it also statically replaces environment variables that appear in the file.\n\n```\n.env                # loaded in all cases\n.env.local          # loaded in all cases, but ignored by git\n.env.[mode]         # only loaded in specified mode\n.env.[mode].local   # only loaded in specified mode, but ignored by git\n```\n\n\n\u003e ignores `.*.local`, so you also need to add it to your project's `.gitignore` file:\n```\n# local env files\n.env.local\n.env.*.local\n```\n\n\n\n## Install\n\n```\nnpm install -D gulp-env-loader\n```\n\n\u003e `Node.js \u003e 12`\n\n\n\n## Usage\n\n1. Create a `.env` file in the root directory of your project, or create different `.env` files for different environments, such as `.env.development`, `.env.production`, etc.\n\n```yml\n# .env configuration\nAPP_MODE=\"development\"\nAPP_API_URL=\"http://test-api.com\"\n```\n\n```yml\n# .env.production configuration\nAPP_MODE=\"production\"\nAPP_API_URL=\"https://api.com\"\n```\n\n2. Create `gulpfile.js`\n```js\nconst gulp = require('gulp')\nconst envInject = require('gulp-env-loader')() //!recommended to put at the beginning and execute immediately\n\n// Output the configured environment variables\nconsole.log('env', envInject.env)\n\ngulp.task('build', function() {\n  return gulp.src('./src/*.js', { sourcemaps: true })\n    .pipe(envInject())\n    .pipe(gulp.dest('./dist', { sourcemaps: '.' }))\n})\n```\n\n3. You can add the runtime parameter `mode` at runtime, which will automatically load the corresponding environment variable configuration file.\n\n```\ngulp build --mode=production\n```\n\n4. Output results\n\nSource file: `./src/api.js`\n```js\nexport function userLogin(params) {\n  return http.post(`${process.env.APP_API_URL}/user/login`, params)\n}\n```\nOutput file: `./dist/api.js`\n```js\nexport function userLogin(params) {\n  return http.post(`https://api.com/user/login`, params)\n}\n```\n\n\n\n## API\n```ts\nrequire('gulp-env-loader')([config])\n```\n\n### config\nAn optional configuration object or configuration file path.  \nIf it is a string, it represents the configuration file path. If it is an object, it can contain the following properties:\n- `path` - (`string`) Configuration file path, default is `.env`\n- `mode` - (`string`) Environment mode name.\n- `modekey` - (`string`) Environment mode key name, default is `mode`\n- `ignoreProcessEnv` - (`boolean`) Turn off writing to `process.env`\n\n\n### Return value\n```js\nenvInject([option])\n```\nCreates a through2 stream for replacing environment variables in file contents.\n\n- `isVar` - (`boolean`) Replaces environment variables with their corresponding string representations (Single quotation marks). Default is `true`.\n- `env` - (`object`) Additional Environment Variables. \n\n\n\n## Thanks\n* [dotenv](https://www.npmjs.com/package/dotenv)\n* [dotenv-expand](https://www.npmjs.com/package/dotenv-expand)\n* https://juejin.cn/post/6993224664705138702\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarinerer%2Fgulp-env-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarinerer%2Fgulp-env-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarinerer%2Fgulp-env-loader/lists"}