Closed brunano21 closed 9 years ago
Hi @brunano21,
if I correctly understand your question then you can use postProcess
functionality (or mergeFunction
, preMerge
).
Could you provide an example? Even if it is not working. Thanks.
Example from documentation.
require('load-grunt-config')(grunt, {
// use different function to merge config files
mergeFunction: require('recursive-merge'),
//can post process config object before it gets passed to grunt
postProcess: function(config) {},
//allows to manipulate the config object before it gets merged with the data object
preMerge: function(config, data) {}
});
so in case of posProcess
you will get result config as an function param, and you can change any data in it before it will be passed to grunt.
Well, I found a possible solution, different from your:
var options = {
configPath: path.join(process.cwd(), '.grunt', 'tasks'),
init: true,
data: {
sharedConfig: grunt.file.readJSON(path.join(process.cwd(), '..', '.grunt' ,'config.json')),
componentConfig: grunt.file.readJSON(path.join(process.cwd(), '.grunt' ,'config.json')),
},
jitGrunt: {
pluginsRoot: '../node_modules',
staticMappings: {
availabletasks: 'grunt-available-tasks'
},
},
};
require('load-grunt-config')(grunt, options);
And then in my less.js
task:
module.exports = function (grunt, options) {
var path = require('path');
var projectRoot = options.sharedConfig.cirrusRoot;
var lessSrc = options.sharedConfig.bowerComp.lessSrc;
var lessFiles = [];
// loading shared less files into lessFiles array
lessSrc.forEach(function(filePath) {
lessFiles.push(path.join(projectRoot, filePath));
});
// loading component less files into lessFiles array
lessFiles.push(options.componentConfig.resources.css);
return {
development: {
files: [
{
expand: true,
cwd: ".",
src: lessFiles,
ext: ".css"
}
]
}
};
};
I know this is not best solution, but what you think?
Another option, you can pass original src
as data: {}
and then use it in subtasks.
For example:
// load-grunt-config
data: {
shared: {
jshint: {
src: '../../..'
}
}
}
// in task config
{
src: '<%= shared.jshint.src %>'
}
@brunano21 we had similar idea at the same time ;)
Lol. In my case I'm using a config.json file containing the configuration stuff I want to share. However yep, we had the same idea :8ball:
It actually doesn't matter how you will pass it to data: {}
object. :)
Hi all,
Let's start saying I'm into a multi project folder, where each folder contains css, js, html files. The folder structure is almost the following:
Basically, I'm using this plugin to override the shared and common tasks as following: (from app1\Gruntfile.js)
With the above code (as explained into the documentation) I'll load the "shared" grunt tasks which live under root/.grunt/ and if then a certain task (let's say root\app1.grunt\jshint.js for example) exists, the
jshint
task will be overridden. That's really awesome! However, I would like to keep the originalsrc
files of the "shared" jshint task (root.grunt\jshint.js), and add a supplementarysrc
folders set defined into thejshint
subtask (root\app1.grunt\jshint.js). How may I sort that out? Thanks!