0

I'm trying to do the following:

gulp.src('js/*.js')
    .pipe(concat('_temp.js'))
    .pipe(gulp.dest('js/'));

gulp.src('build/js/app.js')
    .pipe(replace('// includes', fs.readFileSync('js/_temp.js')))
    .pipe(uglify())
    .pipe(rename('app.min.js'))
    .pipe(gulp.dest('build/js'));

So, I'm concatenating all .js files in js/. The concatenated file is named _temp.js;

After that, I'm reading a app.js and try to replace the // includes string with the concatenated _temp.js file. This doesn't work as node says the file doesn't exist. It does exist though, so I second time I run this task, it works.

This has most probably to do with asynchronisity, but I'm unable to see how I would do this differently?

1 Answer 1

3

You can split your task into 2 and make one of the tasks run after another by using Gulp's dependency resolution system.

gulp.task('task1', function () { ... });
gulp.task('task2', ['task1'], function () { ... });
Sign up to request clarification or add additional context in comments.

1 Comment

You may also want to look at gulpfile.js in this project: github.com/kriasoft/spa-seed.front-end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.