2

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

Nick
  • 13,493
  • 8
  • 51
  • 98

2 Answers2

1

My help is not straightforward but might prove better in the long run. I would suggest not reinventing the wheel and make use of proven packages for mobile app developing. There is a great Yeoman Geneator out there which will deliver an ionic starter project from scratch with all extras like gulp minification included: generator-m-ionic

niklas
  • 2,887
  • 3
  • 38
  • 70
  • Thanks for the link, but i've spent some time to tune this to properly work as i need, and the only thing left to do is this concatenation thing.. i should have probably used the tools you provided before, but right now i don't really want to start everything again – Nick Feb 03 '16 at 15:26
  • reading this http://stackoverflow.com/questions/23384239/excluding-files-directories-from-gulp-task offers the answer i think it should be: gulp.src([path.libs, ignoreIonic])... – niklas Feb 03 '16 at 15:34
  • are you sure path.libs is not empty? – niklas Feb 03 '16 at 15:48
  • then i think you should concat your two arrays first, I think gulp src expects **one** array as argument https://github.com/gulpjs/gulp/blob/master/docs/API.md#globs – niklas Feb 03 '16 at 15:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102496/discussion-between-nick-and-user9). – Nick Feb 03 '16 at 15:57
1

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.

Nick
  • 13,493
  • 8
  • 51
  • 98