我有一个简单的 Gulp 构建过程设置用于测试。我已经多次阅读文档,但似乎无法让 Gulp-inject 将我想要的脚本注入(inject) index.html 文件。
我的 Gulp 文件如下所示:
gulp.task('inject1', function() {
return gulp.src('app/index.html')
.pipe(inject(gulp.src('./app/scripts/app.js', {read : false}))) // Not necessary to read the files (will speed up things), we're only after their paths
.pipe(gulp.dest("dist"));
});
gulp.task('inject2', function() {
return gulp.src('app/scripts/**/*.js', {read : false}) // Not necessary to read the files (will speed up things), we're only after their paths
.pipe(inject("./app/index.html"))
.pipe(gulp.dest("./dist"));
});
这是我的 Index.html 的一部分:
<!-- inject:js -->
<!-- endinject-->
这两个都是从 github 上的文档中复制的。
当我运行这些任务中的任何一个时,控制台只会显示“Started 'inject' Finished 'Inject' '
在我的 ./dist 文件夹中,它创建了一个 Index.html 文件,但没有注入(inject)任何 js 文件。
我尝试过输入 src 并以许多不同的方式注入(inject)属性,但没有运气。知道我做错了什么吗?
最佳答案
首先你的 endinject 标签有错误:
<!-- endinject-->
应该是
<!-- endinject -->
这个插件在各种设置中对我和其他人都非常有用,所以问题可能出在您的配置中。 因为当您使用流式传输时,您无法确定要传输哪些文件,因此请始终尝试使用插件来准确查看您正在传输的文件。我推荐使用 gulp-using .试试这个来调试你的设置:
var debug = require('gulp-debug');
gulp.task('inject2', function() {
return gulp.src('app/scripts/**/*.js', {read : false})
.pipe(debug())
.pipe(inject("./app/index.html"))
.pipe(gulp.dest("./dist"));
});
还要确保您使用相同的方法来验证您是否也匹配您的 html
文件。
除此之外 - 在您了解管道以获取具有正确路径的正确文件之前,这只是反复试验。
如果 gulp-inject
没有注入(inject)任何文件,这意味着你没有正确地管道它们,或者你的目标 inject
不正确。该插件有效,对我来说非常有用。
如果您需要查看示例 工作 gulp 文件,请查看 this gulpfile.js gist
https://stackoverflow.com/questions/23642809/
相关文章:
build - 如何选择哪个 CMake 可执行目标将是默认目标?
android - 构建错误 : Ice cream sandwich emulator on Ub
ios - Xcode 4 - 专用配置设置 : build settings and scheme
iphone - Xcode:为不同的构建配置设置 GCC_PREPROCESSOR_DEFINIT
build - 有人有使用 Gradle 构建 Eclipse RCP 应用程序的经验吗?
java - 无法解析不同风格android studio的方法 'getAllUserGroupB