使用 gulp-inject 将资源注入 index.html 时出现问题。
我有以下应用程序样式、供应商 js 代码和应用程序 js 代码流:
// Vendor JS code
var vendorStream = gulp.src(mainBowerFiles({
paths: {
bowerDirectory: config.bowerDir
},
checkExistence: true
}))
.pipe(concat('vendors.js'))
.pipe(gulp.dest(config.bowerLibDist))
.pipe(size({
title:"Vendor JS code"
}));
// JS App Code
var jsStream = gulp.src(config.jsSrcPath)
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(gulp.dest(config.jsDistFolder))
.pipe(size({
title:"App js code"
}));
// SASS App Code
var cssStream = gulp.src(config.sassSrcPath)
.pipe(sass({
outputStyle: 'compressed'
})
.on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulpIf(config.production, cssnano()))
.on("error", notify.onError(function (error) {
return "Error: " + error.message;
})).pipe(gulp.dest(config.cssDistFolder))
.pipe(size({
title:"Styles"
}));
我想要做的是通过以下任务将 index.ml 注入这些资源并将它们放在 dist 目录中:
gulp.task('inject', function() {
return gulp.src('index.html', {cwd: './app'})
.pipe(inject(es.merge(vendorStream, jsStream, cssStream)))
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest(config.distFolder));
});
这可以正常工作,但问题是路径还包括 dist 目录。这是发布基目录:
// Starts a server using the production build
gulp.task('server', ['build'], function () {
connect.server({
root: './dist',
hostname: '0.0.0.0',
port: 90
});
});
我如何配置 gulp-inject 以便代替
<script src="/dist/js/app.js"></script>
是
<script src="js/app.js"></script>
谢谢 :)