Skip to content

purjus/ng-constants-json-loader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ng-constants-json-loader for webpack

Transform javascript object from json file into an angular module with constants. Each key from the given json object will create a separate constant.

Installation

npm i ng-constants-json-loader --save

Usage

Given a webpack config

module: {
  rules: [
    {
      // Let's take our config file by absolute url
      test: path.resolve(__dirname + 'app/config.json'),
      loader: 'ng-constants-json-loader',
      query: {
        // default
        moduleName: 'constants',
        // Should it be a standalone module:
        //   angular.module('name', [])
        // or not:
        //   angular.module('name')
        standalone: true
      }
    }
  ]
}

and config.json

{
  "api": {
    "url": "http://example.com"
  }, 
  "settings": {
    "lang": "en"
  }
}

includes the json file into your app.js file for being recognised by webpack

require('./config.json');

the loader will emit an angular module

angular.module("constants", [])

  .constant("api", {
    "url": "http://example.com"
  })
  .constant("settings", {
    "lang": "en"
  });

License

MIT (http://www.opensource.org/licenses/mit-license.php)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%