源文件的控制顺序 [英] Control order of source files
问题描述
我需要确保jQuery包含在AngularJS之前,但是自从Angular bower包实际上并不依赖于之后包含的jQuery。
有没有办法将jQuery推到源列表顶部或重写Angular的依赖关系,因此它需要jQuery?
我尝试使用gulp-order插件来做到这一点,但它弄乱了剩余文件的原始顺序:
gulp.task('bower',function(){
var sources = gulp.src(mainBowerFiles(['** / *。 js','!** / * .min.js'])); //不包含最小文件
返回源
//强制jquery成为第一个
.pipe(plugins.order([
'jquery.js',
'*'
)))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat('libs.min.js'))
.pipe(plugins.uglify())
.pipe(插件。 sourcemaps.write('./'))
.pipe(gulp.dest(config.output))
.pipe(plugins.notify({message:'Bower task complete'}));
});
我没有使用 main-bower-files
但我能想到的一个技巧就是直接包含jquery文件,不要将其加载到主bower文件数组中,例如
var glob = ['/path/to/jquery.js'].concat(mainBowerFiles(['**/*.js','!/ path /到/的jquery.js']));
var sources = gulp.src(glob);
I'm using Gulp and the main-bower-files to bundle my bower dependencies.
I need to ensure that jQuery is included before AngularJS, but since the Angular bower package does not actually depend on jQuery it is included after.
Is there a way to push jQuery to the top of source list or override Angular's dependency so it does require jQuery?
I tried using the gulp-order plugin to do this but it messes up the original order of the remaining files:
gulp.task('bower', function () {
var sources = gulp.src(mainBowerFiles(['**/*.js', '!**/*.min.js'])); // don't include min files
return sources
// force jquery to be first
.pipe(plugins.order([
'jquery.js',
'*'
]))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat('libs.min.js'))
.pipe(plugins.uglify())
.pipe(plugins.sourcemaps.write('./'))
.pipe(gulp.dest(config.output))
.pipe(plugins.notify({ message: 'Bower task complete' }));
});
I haven't used main-bower-files
but one trick I can think of is to just include the jquery file directly and don't load it in the main bower files array, e.g.
var glob = ['/path/to/jquery.js'].concat(mainBowerFiles(['**/*.js', '!/path/to/jquery.js']));
var sources = gulp.src(glob);
这篇关于源文件的控制顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!