javascriptgulpgulp-inject

Gulp inject not working


I'm try to use gulp-inject to inject some files into a PHP file. This is not working. I tried using HTML as well but that isn't working. The output in my console says "gulp-inject 6 files into test.html" however there's no files injected. The # of files is correct because I do have 6 JavaScript files in the directory i'm looking at in my Gulp file. Here's my Guilp task:

var inject = require('gulp-inject');

gulp.task('build',function() {

    return gulp.src("src/test.html")
    .pipe(inject(gulp.src("src/vendor/js/*.js")));

});

My test.html file looks like this:

<!DOCTYPE html>
<html>
<head>
    <title>My index</title>
    <!-- inject:css -->
    <!-- endinject -->
</head>
<body>

<!-- inject:js -->
<!-- endinject -->
</body>
</html>

Again, the src/vendor/js directory contains 6 files and the output from Gulp in the console is saying 6 files were added to test.html, but nothing is added. My goal was to do this with PHP but wasn't working so I was testing here with HTML and still, nothing.

Any ideas?

Thanks so much.


Solution

  • The files were injected...but just in memory ! You actually have to pipe the result to a file :

    gulp.task('build',function() {
        return gulp.src("src/test.html")
        .pipe(inject(gulp.src("src/vendor/js/*.js")))
        .pipe(gulp.dest('./dist')); // or .src/ or whatever
    });
    

    There are other examples in the readme