Search code examples
javascriptgulpnunjucks

Multiple data files with Nunjucks


How do I use multiple data files in Nunjucks? — an array of strings does not work for me;

gulp.task('nunjucks', function() {
return gulp.src('src/pages/**/*.+(html|nunjucks)')
    .pipe(data(function() {
      /*DOESN'T WORK*/  return require(['./src/js/variables/media-queries.json', './src/data/data.json'])
    }))
    .pipe(nunjucksRender({
        path: ['src/templates']
    }))
    .pipe(gulp.dest('dist'))
    .pipe(connect.reload());

 });

Solution

  • Using two pipe functions with returns solved this:

    .pipe(data(function() {
            return require ('./src/js/variables/media-queries.json');
        }))
    .pipe(data(function() {
            return require('./src/data/data.json');
        }))