Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load source files from JSON file in Gulpjs

Tags:

json

gulp

I know it's a basic question, but I couldn't find a proper answer.

Is there a way of storing a list of my project's source files in a JSON file and load it on gulpfile.js? For example, instead of doing:

gulp.src(['a.js', 'b.js'])

Do something like:

var sources = some_load_file_func('sources.json');

gulp.src(sources.js_files))
like image 876
Tzach Avatar asked May 13 '14 14:05

Tzach


People also ask

What was used by the gulp file js or JSON?

The gulp tasks are writted in javascript file called gulpfile. js which will be executed by Gulp tool. Gulp can be installed by using npm (Node Package Manager) tool either machine wide or locally to the application.


1 Answers

A gulpfile is just node, and in node you can simply use require on JSON files, like so:

var sources = require('sources.json');

Now sources will be an object (or whatever is in your JSON file).

like image 168
OverZealous Avatar answered Sep 30 '22 15:09

OverZealous