問題描述
我正在嘗試使用 gulp-inject 將一些文件注入 PHP 文件.這是行不通的.我也嘗試過使用 HTML,但這不起作用.我的控制臺中的輸出顯示gulp-inject 6 files into test.html"但是沒有注入文件.# of files 是正確的,因為我在 Gulp 文件中查看的目錄中有 6 個 JavaScript 文件.這是我的 Guilp 任務:
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")));
});
我的 test.html 文件如下所示:
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>
同樣,src/vendor/js 目錄包含 6 個文件,控制臺中 Gulp 的輸出顯示 6 個文件已添加到 test.html,但沒有添加任何內容.我的目標是用 PHP 做到這一點,但沒有工作,所以我在這里用 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.
有什么想法嗎?
非常感謝.
推薦答案
文件被注入...但只是在內存中!您實際上必須將結果通過管道傳輸到文件:
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
});
自述文件中還有其他示例
這篇關于Gulp注入不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!