我正在尝试构建一个 gulp 任务,使用wiredep获取所有bower_components文件,然后将它们连接在一起。然后将我在一个特殊文件夹中的其他一些 JS 文件连接起来,最后缩小所有内容。
问题是我不知道是否可以在 Bower_components 目录之外指定wiredep另一个目录。如果这不可能,我可以使用其他解决方案吗?
我是一个使用 gulp 的初学者,因此如果您能指出我如何看待我的任务的任何其他错误,我们将不胜感激。
var wiredep = require('wiredep')(
{
directory: 'static/bower_components', // default: '.bowerrc'.directory || bower_components
}).stream;
gulp.task('scripts',function(){
return gulp
.src('index.html') //I don´t really know what to put in the src
.pipe(wiredep())
.pipe($.inject(gulp.src("More JS files if wire dep can´t handle them")))
.pipe(minify())
.pipe(gulp.dest('static/dist/src/app.min.js'));
});
最佳答案
我会有一个像这样的方法(可能在项目根目录的配置文件中)来获取您想要使用wiredep连接的任何内容:
getWiredepDefaultOptions: function() {
var options = {
directory: bower.directory,//file path to /bower_components/
};
return options;
},
然后在你的 gulp 任务中,有这样的内容:
gulp.task('wiredep', function() {
log('Wiring the bower dependencies into the html');
var wiredep = require('wiredep').stream;
var options = config.getWiredepDefaultOptions();
return gulp
.src('./index.html')
.pipe(wiredep(options))
.pipe(gulp.dest("wherever you want your index.html"));
});
根据您想要连接的其他内容,您必须使用 index.html 中的标签添加某种排序。
关于javascript - Gulp任务: get files with wiredep concatenate other js files and minify,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38724092/