A
A
Artyom Innokentiev2015-01-02 16:46:08
Node.js
Artyom Innokentiev, 2015-01-02 16:46:08

Why is the main.js file created every other time?

A piece of gulpfile.js :

gulp.task('project:js', function() {
    gulp.src(path.src.js)
        .pipe(uglify())
        .pipe(concat('project.js'))
        .pipe(gulp.dest(path.build.js));
});

gulp.task('vendor:js', function() {
    var vendor = bower_files('**/*.js');
    vendor.push(path.src.semantic_js);
    gulp.src(vendor)
        .pipe(uglify())
        .pipe(concat('vendor.js'))
        .pipe(gulp.dest(path.build.js));
});

gulp.task('build:js', ['vendor:js', 'project:js'], function(){
    gulp.src(['static/build/js/vendor.js', 'static/build/js/project.js'])
        .pipe(concat('main.js'))
        .pipe(gulp.dest(path.build.js));
});

The vendor.js and project.js files are re-created every time, but main.js is re-created every other time. Why?
The callback in build:js works last - checked. Maybe the vendor.js and project.js files do not have time to be created before the callback?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
1vanu4, 2015-01-02
@artinnok

Try to add return in every job.

gulp.task('project:js', function() {
    return gulp.src(path.src.js)
        .pipe(uglify())
        .pipe(concat('project.js'))
        .pipe(gulp.dest(path.build.js));
});

gulp.task('vendor:js', function() {
    var vendor = bower_files('**/*.js');
    vendor.push(path.src.semantic_js);
    return gulp.src(vendor)
        .pipe(uglify())
        .pipe(concat('vendor.js'))
        .pipe(gulp.dest(path.build.js));
});

gulp.task('build:js', ['vendor:js', 'project:js'], function(){
   return gulp.src(['static/build/js/vendor.js', 'static/build/js/project.js'])
        .pipe(concat('main.js'))
        .pipe(gulp.dest(path.build.js));
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question