Gulp inject not working

点点圈 提交于 2019-12-20 02:54:23

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/32768874/gulp-inject-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!