Creates application configuration accessible via require() based on grunt configuration entries.
npm install grunt-create-appconfig> Creates application configuration accessible via require() based on grunt configuration entries.
~0.4.5If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
``shell`
npm install grunt-create-appconfig --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
`js`
grunt.loadNpmTasks('grunt-create-appconfig');
to the data object passed into grunt.initConfig(). grunt.initConfig({
create_appconfig: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific options go here.
},
},
});
$3
#### options.src
Type:
String or ObjectDefault value:
undefinedThe src of configuration data. If src is a
String it is treated as the path to a JSON file containing configuration data. If src is an Object it is treated as the configuration data. This is
a required parameter and there is no default.#### options.dest
Type:
StringDefault value:
'./dist/config.js'The path of the configuration file to be created. If a directory is specified, the file will be given the file name
config.js in the specified directory.$3
#### Default Options
In this example, the default options are used to create a configuration. A src must be specified, so in this case a configuration module would be written to
./dist/config.js exposing a
configuration of {key:dev_value} if create_appconfig:development is run or {key:prod_value} if create_appconfig:production is run. grunt.initConfig({
create_appconfig: {
options: {},
development: {
src: {key:dev_value}
},
production: {
src: {key:prod_value}
},
},
});
#### Custom Options
In this example, custom options are used to create a configuration. A src must be specified and a dest is also specified, so in this case a configuration module would be
written to
./dev_dist/config.js exposing the configuration present in the file config/development.json if create_appconfig:development is run or
a configuration module would be written to ./prod_dist/config.js exposing the configuration present in the file config/production.json if create_appconfig:production` is run.#### Using the Generated Configuration
If, for example, the configuration from the previous default options were used, this configuration could be used in your application in the following manner:
var config = require('./config');
console.log('The value of key is ' + config.key);