{"id":16532426,"url":"https://github.com/sayan751/app-settings-loader","last_synced_at":"2025-03-16T19:31:45.073Z","repository":{"id":34890813,"uuid":"187450694","full_name":"Sayan751/app-settings-loader","owner":"Sayan751","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-22T07:27:19.000Z","size":1590,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-23T10:40:19.069Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Sayan751.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":"2019-05-19T08:13:22.000Z","updated_at":"2024-10-22T07:27:20.000Z","dependencies_parsed_at":"2023-10-04T14:06:27.520Z","dependency_job_id":"d1d438d1-c672-4be9-a9b6-ad771433a146","html_url":"https://github.com/Sayan751/app-settings-loader","commit_stats":{"total_commits":78,"total_committers":4,"mean_commits":19.5,"dds":0.641025641025641,"last_synced_commit":"c8f29a27497e69464e22eef7ff815e2d07202b50"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sayan751%2Fapp-settings-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sayan751%2Fapp-settings-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sayan751%2Fapp-settings-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sayan751%2Fapp-settings-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sayan751","download_url":"https://codeload.github.com/Sayan751/app-settings-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221667315,"owners_count":16860595,"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":[],"created_at":"2024-10-11T18:12:36.867Z","updated_at":"2024-10-27T11:09:44.773Z","avatar_url":"https://github.com/Sayan751.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# app-settings-loader\n\n![build status](https://github.com/Sayan751/app-settings-loader/workflows/build/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/Sayan751/app-settings-loader/badge.svg?branch=master)](https://coveralls.io/github/Sayan751/app-settings-loader?branch=master)\n\n[![NPM](https://nodei.co/npm/app-settings-loader.png)](https://nodei.co/npm/app-settings-loader/)\n\nA simple webpack loader to load and customize application settings based on the provided environment.\n\n## Why\n\nWe often specify the application settings in a JSON file and use it during development; something like below, for example.\n\n```json\n{\n    \"debug\": true,\n    \"endpoint\": \"http://localhost:8080/\",\n    \"basePath\": \"api/\"\n}\n```\n\nHowever, for production (or any other environment) we may need different settings/values for a subset of keys. For example,\n\n```json\n{\n    \"debug\": false,\n    \"endpoint\": \"http://my.awesome.service/\",\n}\n```\n\nUsing this loader, you can bundle environment specific values, given 2 JSON files exist.\n\n## How\n\n### Install\n\n```bash\nnpm i -D app-settings-loader\n```\n\n### Use\n\nLet us assume that we have following directory structure.\n\n```text\nproject_root\n|\n+-config\n| |\n| +-appConfig.json\n| +-appConfig.development.json\n|\n+-main.ts\n+-webpack.config.js\n```\n\nThen you use the `appConfig.json` in `main.ts` as follows.\n\n```typescript\n// with \"resolveJsonModule\": true (and \"esModuleInterop\": true) in your tsconfig\nimport config from \"./config/appConfig.json\";\n\n// or\nconst config = require(\"./config/appConfig.json\");\n```\n\nIn your webpack add the loader as follows.\n\n```javascript\n{\n    test: /appConfig\\.json$/i, // change this as per your file name\n    use: [\n        { loader: \"app-settings-loader\", options: { env: production ? 'production' : 'development' } },\n    ]\n},\n```\n\nWith the above config, the loader will merge the customization coming from the `appConfig.development.json` with the base config in `appConfig.json`, when `production` is truthy.\n\n### How does it work\n\nThe loader has only one option `env` (environment, default value is `\"development\"`). If the base JSON file name is `mysettings.json`, it looks for a JSON file named `mysettings.{env}.json` at the same directory path. If there is one, it merges the customization form that file with the base file, and returns the result. In case there is no customization file, it returns the base content. Note that if you want you may have more environment names, as per your need. That is you may set `env` as [`Betelgeuse5`](https://hitchhikers.fandom.com/wiki/Ford_Prefect), and provided you have a  JSON for that, it will load that too :)\n\n#### Note\n\n- **Merging configurations**: The merge operation keeps the schema of the base file intact. That is, no unknown properties or property value of different type, from the customization files can be applied on the base file. This makes sense because during development you expect a certain set of keys and values of certain datatype to be present in your config and you program against this known schema. Therefore any new keys present in the customization file cannot and should not play any part in the source code.\n- **Valid JSON**: The content of the both base and customization file needs to be valid JSON. Otherwise, it will throw an error.\n- **Do not store sensitive data**: As the config will be part of webpack bundle, you should not store any sensitive data in the customization file. The thumb rule is that any sensitive data that you don't want to keep in your source code, should also not be the part of either base or customization config file.\n\nThat's it. If you face any problem, feel free to open an issue.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayan751%2Fapp-settings-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsayan751%2Fapp-settings-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayan751%2Fapp-settings-loader/lists"}