Reputation: 486
Recently we created a separate codebase for our mobile site m.xyz.com and optimized it for performance. We implemented grunt in that codebase. Now, we are planning to use the same codebase for our upcoming new desktop version. so, we are structuring one codebase as mobile / desktop.
Now, the whole project have only one Gruntfile.js written for mobile. How can I split the task for mobile / desktop ? Say, if I execute "grunt mobile" mobile gruntfile.js get executed. If I type "grunt desktop" desktop gruntfile.js get executed. Are there any other way to resolve this scenario ?
Upvotes: 1
Views: 128
Reputation: 486
I created two file Gruntfile.mobile.js and Gruntfile.desktop.js
My Gruntfile.js look like this
'use strict';
module.exports = function(grunt) {
if (grunt.option("option") == 'mobile') {
require('./Gruntfile.mobile.js')(grunt);
} else if (grunt.option("option") == 'desktop') {
require('./Gruntfile.desktop.js')(grunt);
}
};
My command line: grunt --option=mobile
for mobile and grunt --option=desktop
for desktop
Upvotes: 0
Reputation: 76209
If you don't want to parse the command line arguments yourself, it would make the most sense to set an option. Call it like grunt task --mobile
.
module.exports = function (grunt) {
if(grunt.option('mobile')) {
require('Gruntfile.mobile.js')(grunt);
} else if(grunt.option('desktop')) {
require('Gruntfile.desktop.js')(grunt);
}
}
Upvotes: 1