Skip to content

Instantly share code, notes, and snippets.

@maxov
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxov/9884886 to your computer and use it in GitHub Desktop.
Save maxov/9884886 to your computer and use it in GitHub Desktop.
An explanation of how to share variables between Gulp and Grunt

Sharing variables between Gulp and Grunt

Gulp, while being a great build system, isn't perfect. Its plugin system is immature and not as full-featured as Grunt. I created gulp-grunt as a remedy for this problem, making it possible to import tasks from Grunt to gulp.

However, sometimes you want to use variables in both files. How? Well, use an accessory file to define all your variables, and import it from both.

In this gist is an example(a terrible one at that, but whatever) of importing stuff from an external file.

var paths = require('./paths');
module.exports = function(grunt) {
// Project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
'myproject': {
// may need to use grunt expansion
src: [paths.src],
dest: paths.dest + paths.destFile
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
// Default task
};
var gulp = require('gulp');
var concat = require('gulp-concat');
// Loading paths
var paths = require('./paths');
gulp.task('concat', function () {
return gulp.src(paths.src)
.pipe(concat(paths.destFile))
.pipe(gulp.dest(paths.dest));
});
// I put all my paths in here
exports.src = 'src/js/**/*';
exports.dest = 'build/';
exports.destFile = 'concat.js';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment