{"id":17793438,"url":"https://github.com/firstandthird/load-grunt-config","last_synced_at":"2025-05-15T15:05:11.501Z","repository":{"id":10600111,"uuid":"12814992","full_name":"firstandthird/load-grunt-config","owner":"firstandthird","description":"Grunt plugin that lets you break up your Gruntfile config by task","archived":false,"fork":false,"pushed_at":"2023-04-15T14:24:07.000Z","size":490,"stargazers_count":373,"open_issues_count":21,"forks_count":62,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-31T19:09:11.213Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"firstandthird.github.io/load-grunt-config/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/firstandthird.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-13T17:14:07.000Z","updated_at":"2024-11-19T08:23:15.000Z","dependencies_parsed_at":"2024-06-18T12:20:44.470Z","dependency_job_id":"f5a8c8a1-1b9c-403d-af96-22e1344bf469","html_url":"https://github.com/firstandthird/load-grunt-config","commit_stats":{"total_commits":185,"total_committers":38,"mean_commits":4.868421052631579,"dds":0.518918918918919,"last_synced_commit":"1d2d7d00e92643e7cf4219e85a21a27abbbbb924"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fload-grunt-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fload-grunt-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fload-grunt-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fload-grunt-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstandthird","download_url":"https://codeload.github.com/firstandthird/load-grunt-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247721898,"owners_count":20985084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-27T11:08:52.966Z","updated_at":"2025-04-07T20:09:47.730Z","avatar_url":"https://github.com/firstandthird.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# load-grunt-config [![Build Status](https://travis-ci.org/firstandthird/load-grunt-config.svg?branch=master)](https://travis-ci.org/firstandthird/load-grunt-config)\n\nload-grunt-config is a Grunt library that allows you to break up your Gruntfile config by task.  For most small projects a single Gruntfile.js is perfect. But as a project grows, the Gruntfile.js can quickly become unmanagable; this is where load-grunt-config comes in handy.  It was heavily inspired by [Thomas Boyt's \"More Maintainable Gruntfiles\"](http://thomasboyt.github.io/2013/09/01/maintainable-grunt.html).\n\n## Features\n\n- Each task has its own config file. Example: jshint.js, mocha.js, etc.\n- Auto load all grunt plugins.  Uses [load-grunt-tasks](https://github.com/sindresorhus/load-grunt-tasks). (Optionally it can use [jit-grunt](https://github.com/shootaroo/jit-grunt))\n- Auto expose package.json (`\u003c%= package.name %\u003e`).\n- Support for YAML files.\n- Support for CSON files.\n- Support for returning a function.\n- [Easily register task aliases](#aliases) with `aliases.(js|json|yaml)`.\n- [Config overrides](#custom-config)\n- [Config grouping](#config-grouping)\n\n## Installation\n\n```bash\nnpm install -D load-grunt-config\n```\n\n## Example\n\nBasic Gruntfile.js\n```javascript\nmodule.exports = function(grunt) {\n\n\trequire('load-grunt-config')(grunt);\n\n};\n```\n\nGruntfile.js with options\n```javascript\nmodule.exports = function(grunt) {\n\tvar path = require('path');\n\n\trequire('load-grunt-config')(grunt, {\n\t\t// path to task.js files, defaults to grunt dir\n\t\tconfigPath: path.join(process.cwd(), 'grunt'),\n\t\t\n\t\t// path to project package.json file\n\t\tpackageJsonPath: path.join(process.cwd(), 'package.json'),\n\n\t\t// auto grunt.initConfig\n\t\tinit: true,\n\n\t\t// data passed into config.  Can use with \u003c%= test %\u003e\n\t\tdata: {\n\t\t\ttest: false\n\t\t},\n\n\t\t// use different function to merge config files\n\t\tmergeFunction: require('recursive-merge'),\n\n\t\t// can optionally pass options to load-grunt-tasks.\n\t\t// If you set to false, it will disable auto loading tasks.\n\t\tloadGruntTasks: {\n\t\t\n\t\t\tpattern: 'grunt-*',\n\t\t\tconfig: require('./package.json'),\n\t\t\tscope: 'devDependencies'\n\t\t},\n\n\t\t//can post process config object before it gets passed to grunt\n\t\tpostProcess: function(config) {},\n\n\t\t//allows to manipulate the config object before it gets merged with the data object\n\t\tpreMerge: function(config, data) {}\n\t});\n\n};\n```\n\nOptionally you can use [jit-grunt](https://github.com/shootaroo/jit-grunt) instead of [load-grunt-tasks](https://github.com/sindresorhus/load-grunt-tasks)\n```javascript\nmodule.exports = function(grunt) {\n\n\trequire('load-grunt-config')(grunt, {\n\t\t// ...\n\t\tjitGrunt: {\n\t\t    // here you can pass options to jit-grunt (or just jitGrunt: true)\n\t\t    staticMappings: {\n\t\t        // here you can specify static mappings, for example:\n\t\t        sprite: 'grunt-spritesmith',\n                hello: 'custom/say-hello.js'\n\t\t    }\n\t\t}\n\t});\n\n};\n```\n\nNote: if you have problems with auto loading of some tasks please check [jit-grunt#static-mappings](https://github.com/shootaroo/jit-grunt#static-mappings)\n\n### Grunt tasks files\n\nHere's what the files in your `grunt/` folder could look like.  You can use either .js, .json, .yaml,  or .cson - whatever you prefer and you can mix and match as you see fit.\n\nExample js file returning an object - `grunt/watch.js`\n```javascript\nmodule.exports = {\n  all: {\n    files: [\n      '\u003c%= jshint.all %\u003e',\n      'grunt/*.yaml'\n    ],\n    tasks: [\n      'default'\n    ]\n  }\n};\n```\n\nExample js file returning a function - `grunt/jshint.js`\n```javascript\nmodule.exports = function (grunt, options) {\n  return {\n    all: [\n      'Gruntfile.js',\n      'grunt/*.js',\n      'lib/*.js',\n      'test/*.js',\n      options.someFile\n    ]\n  };\n};\n```\n\nExample json file - `grunt/clean.json`\n```json\n{\n  \"all\": [\n    \"\u003c%= project.dest %\u003e\",\n    \"target/*.js\"\n  ]\n}\n```\n\nExample yaml file - `grunt/notify.yaml`\n```yaml\ndefault:\n  options:\n    message: 'Default finished'\n```\n\n### Aliases\n\nIf your `grunt/` folder contains an `aliases.(js|.json|yaml|cson)` file, `load-grunt-config` will use that to define your tasks aliases (like `grunt.registerTask('default', ['jshint']);`).\n\nThe following examples show the same `aliasses` definition written in various formats\n\nExample yaml file - `grunt/aliases.yaml`\n```yaml\ndefault: []\n\nlint:\n  description: 'Helps to make our code better'\n  tasks:\n    - 'jshint'\n    - 'csslint'\n\nbuild:\n  - 'lint'\n  - 'mocha'\n  - 'notify'\n```\n\nExample json file - `grunt/aliases.json`\n```json\n{\n  \"default\": [],\n  \"lint\": [\n    \"jshint\",\n    \"csslint\"\n  ],\n  \"build\": [\n    \"lint\",\n    \"mocha\",\n    \"notify\"\n  ]\n}\n```\n\nExample JavaScript file returning an object - `grunt/aliases.js`\n```javascript\nmodule.exports = {\n  'default': [],\n  'lint': [\n    'jshint',\n    'csslint'\n  ],\n  'build': [\n    'lint',\n    'mocha',\n    'notify'\n  ]\n};\n```\n\nExample JavaScript file returning a function `grunt/aliases.js`\nUseful if there is need to compute something before return.\n\n```javascript\nmodule.exports = function (grunt, options) {\n  // computation...\n  return {\n    'default': [],\n    'lint': [\n      'jshint',\n      'csslint'\n    ],\n    'build': [\n      'lint',\n      'mocha',\n      'notify'\n    ]\n  };\n};\n```\n\nYou can specify a task description - example JavaScript file `grunt/aliases.js`\n```javascript\nmodule.exports = {\n  'lint': {\n    description: 'Lint css and js',\n    tasks: [\n      'jshint',\n      'csslint'\n    ]\n  }\n};\n```\n\n### Custom Config\n\nThere are certain scenarios where you might have a base config for your team, and you want to be able to override some of the config based on your personal setup.  You can do that with the `overridePath` property.  In this case, the library will merge the two, with the override path taking priority.  For example:\n\n```javascript\nmodule.exports = function(grunt) {\n  var path = require('path');\n  \n  require('load-grunt-config')(grunt, {\n    configPath: path.join(process.cwd(), 'vendor'),\n    overridePath: path.join(process.cwd(), 'config-'+process.env.USER)\n  });\n\n};\n```\n\n`configPath` and `overridePath` accept single string as well as array of strings.  It means that you can compose config using multiple folders.  For example:\n\n```javascript\nmodule.exports = function(grunt) {\n  var path = require('path');\n  \n  require('load-grunt-config')(grunt, {\n    configPath: [\n      path.join(process.cwd(), 'vendor'),\n      path.join(process.cwd(), 'base-target')\n    ],\n    overridePath: [\n      path.join(process.cwd(), 'variant-1'),\n      path.join(process.cwd(), 'variant-n')\n    ]\n  });\n\n};\n\n```\n\n### Config Grouping\n\n`load-grunt-config` also supports grouping tasks.  This is handy when you want to group all of your script or css tasks together.  To do that, just add the suffix `-tasks` to your config filename and `load-grunt-config` will treat the filename as the task target and the top level keys as the task names.\n\nHere's an example\n\nFilename: `/config/scripts-tasks.yaml`\n```yaml\njshint:\n  files:\n    - '*.js'\njshint__test:\n  files:\n    - 'test/*.js'\nwatch:\n  files:\n    - '*.js'\n  tasks:\n    - 'scripts'\n```\n\nThis would be the equivalent in your `Gruntfile.js`:\n```javascript\n{\n  jshint: {\n    scripts: {\n      files: [\n        '*.js'\n      ]\n    },\n    scripts_test: {\n      files: [\n        'test/*.js'\n      ]\n    }\n  },\n  watch: {\n    scripts: {\n      files: [\n        '*.js'\n      ],\n      tasks: [\n        'scripts'\n      ]\n    }\n  }\n}\n```\n\n### Debugging\n\nIf you pass the parameter `--config-debug`, `load-grunt-config` will output the whole object it will pass\nto Grunt, which can be useful for debugging purposes or when asking for help.\n\nNote that this won't run grunt at all and no tasks would be run, nor loaded.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fload-grunt-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstandthird%2Fload-grunt-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fload-grunt-config/lists"}