{"id":14973278,"url":"https://github.com/gshigeto/ionic-environment-variables","last_synced_at":"2025-09-03T09:34:57.442Z","repository":{"id":74482919,"uuid":"101956253","full_name":"gshigeto/ionic-environment-variables","owner":"gshigeto","description":"Easy to use environment variables for Ionic3!","archived":false,"fork":false,"pushed_at":"2018-05-05T17:26:21.000Z","size":1676,"stargazers_count":277,"open_issues_count":15,"forks_count":35,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-07T04:07:58.979Z","etag":null,"topics":["angular4","environment-variables","environments","ionic","ionic-framework","ionic3","ionic3-examples"],"latest_commit_sha":null,"homepage":null,"language":"CSS","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/gshigeto.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-08-31T03:42:27.000Z","updated_at":"2024-09-19T17:27:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"99a876ae-d2e1-4c33-aa38-0729b049d870","html_url":"https://github.com/gshigeto/ionic-environment-variables","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"94224b27820e807c960ac578c190c7a3272d5b9b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gshigeto%2Fionic-environment-variables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gshigeto%2Fionic-environment-variables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gshigeto%2Fionic-environment-variables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gshigeto%2Fionic-environment-variables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gshigeto","download_url":"https://codeload.github.com/gshigeto/ionic-environment-variables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252810273,"owners_count":21807759,"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":["angular4","environment-variables","environments","ionic","ionic-framework","ionic3","ionic3-examples"],"created_at":"2024-09-24T13:48:28.695Z","updated_at":"2025-05-07T04:08:07.810Z","avatar_url":"https://github.com/gshigeto.png","language":"CSS","readme":"# Ionic Environment Variables\n\nWith this configuration, you can import environment variables anywhere, even in your `app.module.ts`.\nAlso supports any number of custom environments (prod, staging, dev, etc.)\nThis project uses the [@ionic/app-script](https://github.com/ionic-team/ionic-app-scripts) package. I recommend updating/installing this package before starting.\n\nAdd the following to your `package.json`:\n```json\n\"config\": {\n  \"ionic_webpack\": \"./config/webpack.config.js\"\n}\n```\n\nAdd the following to your `tsconfig.json` in `compilerOptions`:\n```json\n\"baseUrl\": \"./src\",\n\"paths\": {\n  \"@app/env\": [\n    \"environments/environment\"\n  ]\n}\n```\n\nCreate a file in your base directory `config/webpack.config.js` and paste the following:\n```javascript\nvar chalk = require(\"chalk\");\nvar fs = require('fs');\nvar path = require('path');\nvar useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js');\n\nvar env = process.env.IONIC_ENV;\n\nuseDefaultConfig.prod.resolve.alias = {\n  \"@app/env\": path.resolve(environmentPath('prod'))\n};\n\nuseDefaultConfig.dev.resolve.alias = {\n  \"@app/env\": path.resolve(environmentPath('dev'))\n};\n\nif (env !== 'prod' \u0026\u0026 env !== 'dev') {\n  // Default to dev config\n  useDefaultConfig[env] = useDefaultConfig.dev;\n  useDefaultConfig[env].resolve.alias = {\n    \"@app/env\": path.resolve(environmentPath(env))\n  };\n}\n\nfunction environmentPath(env) {\n  var filePath = './src/environments/environment' + (env === 'prod' ? '' : '.' + env) + '.ts';\n  if (!fs.existsSync(filePath)) {\n    console.log(chalk.red('\\n' + filePath + ' does not exist!'));\n  } else {\n    return filePath;\n  }\n}\n\nmodule.exports = function () {\n  return useDefaultConfig;\n};\n```\n\nCreate a default file `src/environments/environment.ts` which will be used for your **PRODUCTION** environment:\n```typescript\nexport const ENV = {\n  mode: 'Production'\n}\n```\n\nCreate a default file `src/environments/environment.dev.ts` which will be used for your development environment:\n```typescript\nexport const ENV = {\n  mode: 'Development'\n}\n```\n\nYou can then import your environment variables anywhere!\n```typescript\nimport { ENV } from '@app/env'\n```\n\n**NOTE** Remember to ignore your files in your `.gitignore`\n```\n# Envrionment Variables\n**/environment.*\n!**/environment.model.ts\n```\n\nTo test production builds: `ionic build --prod` then open the www/index.html file in your browser.\n# If more than `prod` and `dev` environments are wanted\n\n1. Change your `webpack.config.js` `IONIC_ENV` variable to be something else. For example:\n```javascript\nvar env = process.env.MY_ENV;\n```\n2. Add to your `package.json` another run script and name it whatever you would like\n```json\n\"serve:testing\": \"MY_ENV=testing ionic-app-scripts serve\"\n```\n3. Create your testing file `src/environments/environment.testing.ts`. This should be whatever you set your `MY_ENV` to.\n4. Finally, run the script by using the name you used for your script in `package.json`\n```bash\n$ npm run serve:testing\n```\n\n**NOTE**: When running with a custom variable, production builds still need `--prod` flag","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgshigeto%2Fionic-environment-variables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgshigeto%2Fionic-environment-variables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgshigeto%2Fionic-environment-variables/lists"}