我有 2 个 html 文件 index.html 和 build.html。
构建.html
<!-- build:js({.tmp/serve,www,src,.tmp/partials}) scripts/vendor.js -->
<!-- bower:js -->
<!-- run `gulp wiredep` to automaticaly populate bower script dependencies -->
<!-- endbower -->
<script src="../bower_components/angulartics/src/angulartics.js"></script>
<script src="../bower_components/owl.carousel/dist/owl.carousel.js"></script>
<!-- endbuild -->
<!-- build:js({.tmp/serve,www,src,.tmp/partials}) scripts/app.js -->
<!-- inject:js -->
<!-- endinject -->
<!-- endbuild -->
<!-- compiled css output -->
<!-- <link href="css/ionic.app.css"
rel="stylesheet"> -->
<!-- ionic/angularjs js -->
<!-- <script src="lib/ionic/js/ionic.bundle.js"></script> -->
<!-- config options -->
<!-- <script src="config/app-config.js"></script> -->
<!-- run `gulp wiredep` to automaticaly populate bower styles dependencies -->
<!-- endbower -->
<!-- endbuild -->
<!-- build:css({.tmp/serve,src}) styles/app.css -->
<!-- inject:css -->
<!-- css files will be automaticaly insert here -->
<!-- endinject -->
<!-- endbuild -->
索引.html
<html>
<head>
</head>
<body>
// inject: %HTML5:DYNAMIC:SRC:BUILD%
</body>
</html>
在 build.html 具有实际的 js 和 css 文件之后,我需要将 build.html 的内容注入 index.html。下面我附上 gulp 任务。
吞咽文件
gulp.task('inject, function () {
var injectStyles = gulp.src([
paths.tmp + '/serve/**/*.css',
'!' + paths.tmp + '/serve/module/vendor.css',
'!' + paths.tmp + '/serve/app/vendor.css'
], {
read: false
});
var injectScripts = gulp.src(gulp.sources.js)
.pipe($.angularFilesort().on('error', $.util.log));
var injectOptions = {
ignorePath: [paths.src, paths.tmp + '/serve', paths.tmp + '/partials'],
addRootSlash: false
};
var wiredepOptions = {
directory: 'bower_components',
// TODO: Revisit these excludes, delete this comment
exclude: [/angulartics/, /sha1/]
};
return gulp.src('build.html')
.pipe($.inject(injectStyles, injectOptions))
.pipe($.inject(injectScripts, injectOptions))
.pipe(wiredep(wiredepOptions))
.pipe(injectfile({
pattern: '//\\s*inject:<filename>|/*\\s*inject:<filename> '
}))
.pipe(gulp.dest(paths.tmp + '/serve'));
});
gulp.task('inject-build',['inject'], function () {
return gulp.src(paths.src + '/index.html')
.pipe(replace('%HTML5:DYNAMIC:SRC:BUILD%', paths.tmp + '/serve/build.html'))
.pipe(gulp.dest(paths.tmp + '/serve'));
})
现在发生的事情是,代替 index.html 中的“//注入:%HTML5:DYNAMIC:SRC:BUILD%”,正在获取“build.html”文件路径。感谢任何解决此问题的见解。