0

My project uses two different code bases - one for desktop and one for mobile. I'd like to use the same gulp "build" task for both. My gulp "build" task for desktop looks like this:

gulp.task('build', function() {
  return gulp.src([
    'file1.js',
    'file2.js',
    'file3.js',
    'file4.js',
    'file5.js',
    'file6.js',
    'file7.js',
    'file8.js',
    'file9.js',
    'file10.js',
  ])
  .pipe(concat('bundle.js'))
  .pipe(uglify())
  .pipe(gulp.dest('desktop/dist'));
});

The only differences between these tasks is:

1) the list of files being concatenated into bundle.js

2) the prefixing dist/bundle.js with "desktop/" or "mweb/" based on which platform I'm compiling code for

Ideally, the task would be generic enough to where I could pass in a different array of files (perhaps using a function argument and/or variables), but am struggling with how to achieve this using gulp.

What I've tried so far:

My first approach was to create two separate build tasks, "desktop-build" and "mobile-build", but this approach feels bloated and redundant.

manh2244
  • 133
  • 1
  • 2
  • 15

1 Answers1

0

I recommend looking at this question Pass Parameter to Gulp Task. You can define, for example, an environment variable object which contains an environment name, prefix, file list, and any other useful information, then check for a flag like, gulp build --desktop to use the corresponding environment attributes in the build process, with the most common use case as a default environment. Seems the easiest and most flexible option.

Community
  • 1
  • 1
Peter Behr
  • 607
  • 1
  • 5
  • 16