Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

grunt.config


May 25, 2021 Grunt


Table of contents


grunt.config

Get configuration data for the current project from Gruntfile

Note that any method marked ☃ (unicode snowman) can also be accessed directly through the grunt object; this Please know.

Initialize the configuration data

Note that the methods listed below can also be accessed through the grunt object in grunt.initConfig

grunt.config.init

Initialize a configuration object for the current project. T he incoming configObject be used in subsequent task and can be accessed through the grunt.config method. Gruntfile almost every project.

grunt.config.init(configObject)

Note that <% %> until configuration data is taken.

The following example shows the configuration data for the jshint task in the grunt-contrib-jshint plug-in: jshint

grunt.config.init({
  jshint: {
    all: ['lib/*.js', 'test/*.js', 'Gruntfile.js']
  }
});

Check out get started guides for more configuration cases.

This method can also grunt.initConfig

Get configuration data

The following methods allow Grunt configuration data to be accessed either via dot-delimited string like 'pkg.author.name' or via array of property name parts like ['pkg', 'author', 'name'] .

Note that if a specified property name contains a . dot, it must be escaped with a literal backslash, eg. 'concat.dist/built\\.js' . If an array of parts is specified, Grunt will handle the escaping internally with the grunt.config.escape method.

grunt.config

Get or set a value from the project's Grunt configuration. T his method serves as an alias for other methods; if two arguments are passed, grunt.config.set is grunt.config.get called. G et or set a value from the project's grunt configuration. T his method serves as an alias to other methods; if two arguments are passed, grunt.config.set is called, otherwise grunt.config.get is called.

grunt.config([prop [, value]])

grunt.config.get

Get a value from the project's Grunt configuration. If prop is specified, that property's value is returned, or null if that property is not defined. If prop isn't specified, a copy of the entire config object is returned. Templates strings will be recursively processed using the grunt.config.process method.

grunt.config.get([prop])

grunt.config.process

Process a value, recursively expanding <% %> templates (via the grunt.template.process method) in the context of the Grunt config, as they are encountered. this method is called automatically by grunt.config.get but not by grunt.config.getRaw .

grunt.config.process(value)

If any retrieved value is entirely a single '<%= foo %>' or '<%= foo.bar %>' template string, and the specified foo or foo.bar property is a non-string (and not null or undefined ) value, it will be expanded to the actual value. That, combined with grunt's task system automatically flattening arrays, can be extremely useful.

grunt.config.getRaw

Get a raw value from the project's Grunt configuration, without processing <% %> template strings. If prop is specified, that property's value is returned, or null if that property is not defined. If prop isn't specified, a copy of the entire config object is returned.

grunt.config.getRaw([prop])

grunt.config.set

Set a value for a property in the Grunt configuration of the current project.

grunt.config.set(prop, value)

Note that <% %> until configuration data is taken.

grunt.config.escape

Ignore the . in . a propString D ot. T his should be used for property names that contain dots. E scape . dots in the given propString . This should be used for property names that contain dots.

grunt.config.escape(propString)

grunt.config.merge

Added in 0.4.5

Recursively merges properties of the specified configObject into the current project configuration.

grunt.config.merge(configObject)

You can use this method to append configuration options, targets, etc., to already defined tasks, for example:

grunt.config.merge({
  watch: {
    files: ["path/to/files"],
    tasks: ["task"]
  }
});

Requiring Config Data

Note that the methods listed below can be accessed this through this object in the form of this.requiresConfig

grunt.config.requires

If one or more configuration properties are required that do not null of null or undefined the current task will fail. This method can specify one or more strings and configure an array of properties as arguments.

grunt.config.requires(prop [, prop [, ...]])

This method is called inside this.requiresConfig