我正在使用咖啡脚本生成我的 js,我可以将它从 src 文件夹生成到 dist 文件夹。现在尝试使用 gulp-inject 自动加载这些文件,以下是我的代码。
gulpfile.js
gulp.task('inject', function () {
var target = gulp.src('./dist/index.html');
// It's not necessary to read the files (will speed up things), we're only after their paths:
var sources = gulp.src(['./scripts/**/*.js','./partials/**/*.js', './styles/**/*.css'], {read: false},{relative: false});
return target.pipe(plugins.inject(sources))
.pipe(gulp.dest('./dist'));
});
结果输出来自 dist/index.html
<!--inject:js--><script src="/dist/scripts/app.js"></script><script src="/dist/scripts/config.js"></script><script src="/dist/scripts/routes.js"></script><script src="/dist/partials/home/home.controller.js"></script><!--endinject-->
我希望它像 scripts/routes.js 和 scripts/config.js
当我使用浏览器同步时,它指向作为根文件夹的 dist 文件夹。我尝试了组合,但没有安装任何东西。指出我正确的代码。