3

I am really new to gulp and I am struggling with making a build process which seems fairly simple but I am not able to crack it.

What I want to achieve is that all my js and css files to be bundled and bundled to be named as all_*.min.js where * is current timestamp and delete the old all_*.min.js bundle.

My another challenge is that how to detect the change in bundle when one of the files of bundle is changed without watch. In short this is what I want to achieve. Any suggestions would be of great help.

Thanks in advance.

gulp.task('scripts', function () {
gulp.src(['js/*.js']) // folder of individual js files
.pipe(changed('build/js/')) // build folder for all the bundles
.pipe(ngAnnotate())  // get only those files which are changed
.pipe(deletefile({ reg: '*.min.js', deleteMatch: false })) // delete old bundles which contains changes
.pipe(concat('scripts.js')) // concatnate files to form new bundle
.pipe(uglify()) // uglify it
.pipe(rename({ suffix: (new Date()).getTime() + '.min'})) // do versioning 
.pipe(gulp.dest('build/js/')); // place it in final build folder
});
Aadil Keshwani
  • 1,385
  • 1
  • 18
  • 29

0 Answers0