admin管理员组

文章数量:1313364

How do people handle mon configuration options in Grunt for multiple projects. The projects would share some mon configuration options, e.g. for min, but also have private or custom configuration settings per project, e.g. only one out of three projects requires less or has different options for it.

Is there a way to share this mon configuration between the projects, using inheritance or importing an existing file, or does each project have to define all settings?

The projects I'm referring to would reside in a directory hierarchy like

root
    module1
         grunt.js
    module2
         grunt.js
    module3
         grunt.js

Is there some way to provide mon configuration settings at the root level?

How do people handle mon configuration options in Grunt for multiple projects. The projects would share some mon configuration options, e.g. for min, but also have private or custom configuration settings per project, e.g. only one out of three projects requires less or has different options for it.

Is there a way to share this mon configuration between the projects, using inheritance or importing an existing file, or does each project have to define all settings?

The projects I'm referring to would reside in a directory hierarchy like

root
    module1
         grunt.js
    module2
         grunt.js
    module3
         grunt.js

Is there some way to provide mon configuration settings at the root level?

Share Improve this question asked Nov 19, 2012 at 16:48 nwinklernwinkler 54.5k23 gold badges164 silver badges169 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

You can easily store configuration in as many external JSON files as you need. grunt.file.readJSON will help you here. For example:

module.exports = function(grunt) {

  var concatConf = grunt.file.readJSON('../concat-mon.json'),
      minConf = grunt.file.readJSON('../min-mon.json');

  // do whatever you want with concatConf and minConf here
  // ...

  // Project configuration.
  grunt.initConfig({
    pkg: '<json:grunt-sample.jquery.json>',
    meta: {
      banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
        '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
        '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
        '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
        ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
    },

    concat: concatConf,
    min: minConf

    // ...
  });

  // Default task.
  grunt.registerTask('default', 'concat min');

};

Don't forget that a gruntfile is a regular JavaScript file executed in Node environment and configuration options are regular JavaScript objects :)

本文标签: javascriptInheritance for common configuration options in gruntjs configurationStack Overflow