Giter Club home page Giter Club logo

app-json-config-loader's Introduction

app-json-config-loader

Loads configuration as declared in the json-file scopes. Loader uses get-json-config as core to get scopes of configuration you stored. Tranform list of scopes of configuration to configuration object at build by webpack allows you to divide your configuration by scopes (for instance, configuration for api, database, logging modules), define which scopes must be shared between client and server and which must not be shared (database credentails must not to included to cleint bundle).

Requirements

This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.

Getting Started

To begin, you'll need to install app-json-config-loader:

$ npm install --save-dev app-json-config-loader

Then add the loader to your webpack config. For example:

// config/api.json
{
  "production": {
    "endPoint": "/api/v1"
  },
  "development": {
    "endPoint": "/dev_api/"
  },
  "test": {
    "endPoint": "/dev_api/"
  }
}
// config/database.json
{
  "production": {
    "host": "db.expamle.host",
    "port": 27017,
    "username": "produsername",
    "password": "prodpassword"
  },
  "development": {
    "host": "localhost",
    "port": 27017,
    "username": "devusername",
    "password": "devpassword"
  },
  "test": {
    "host": "localhost",
    "port": 27117,
    "username": "testusername",
    "password": "testpassword"
  }
}
// src/client/configs.json
["api"]
// src/server/configs.json
["api", "database"]
// webpack.server.config.js
module.exports = (env) => {
  module: {
    rules: [
      {
        test: /server\/configs\.json$/,
        use: [
          {
            loader: "app-json-config-loader",
            options: {
              env,                    // default process.env.NODE_ENV || "development",
              configPath: "./config"  // default "./config",
            }
          },
        ],
      },
    ],
  },
};
// src/server/entry.js
const config = require('./configs.json');

// if development mode config will be:
//   {
//     api:
//       { endpoint: '/dev_api' },
//     database: {
//       host: "localhost",
//       port: 27017,
//       username: "devusername",
//       password: "devpassword"
//     }
//   }
// src/client/entry.js
const config = require('./configs.json');

// if production mode config will be:
//   {
//     api:
//       { endpoint: '/dev_api' },
//   }

And run webpack via your preferred method.

License

app-json-config-loader's People

Contributors

unmyke avatar

Watchers

James Cloos avatar

app-json-config-loader's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.