Search code examples
ionic-frameworkgulpgulp-concat

Gulp concat - all files except for some


I've been searching a while for this but with no luck.

I'm trying to write a gulp task that should concatenate all js files inside my lib folder, except for some.

I tried with the following, using gulp-ignore, but with no luck:

var gulpIgnore = require('gulp-ignore');

var ignoreIonic = '!./www/lib/ionic/';

gulp.task('unify-libs', function () {
    gulp.src(paths.libs)
        .pipe(sourcemaps.init())
        .pipe(ngAnnotate({
            single_quotes: true
        }))
        .pipe(gulpIgnore.exclude(ignoreIonic))
        .pipe(concat('libs.js'))
        .pipe(uglify())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('./src/js'));
});

My folder structure is the following:

www
 |--lib
    |--ionic
    |   |--css
    |   |--fonts
    |   |--js
    |   |   |--angular
    |   |   |--angular-ui
    |   |   |--ionic.bundle.js
    |   |   |--ionic.bundle.min.js
    |   |   |--ionic.js
    |   |   |--ionic.min.js
    |   |   |--ionic-angular.js
    |   |   |--ionic-angular.min.js
    |   |--scss
    |--test.js

What i'm trying to achieve with the gulp task is:

I wanna concatenate all files inside lib folder, but inside ionic->js i want to concatenate only ionic.bundle.min.js to the final javascript and NOT all the files.

Any help? thanks


Solution

  • At the end, i solved in this way:

    var paths = {
        libs: ['./www/lib/**/*.js', '!./www/lib/ionic/**'],
        ....
    };
    
    gulp.task('unify-libs', function () {
        gulp.src(paths.libs)
            .pipe(sourcemaps.init())
            .pipe(ngAnnotate({single_quotes: true}))
            .pipe(concat('libs.js'))
            .pipe(uglify())
            .pipe(sourcemaps.write())
            .pipe(gulp.dest('./src/' + appRelease + '/js'));
    });
    

    and it is now compiling all files inside lib folder, except for any file inside ionic folder. I just decided to copy the only file i needed directly in my src folder, it makes my life easier.

    Hope it helps.