Say, for example, you are building a project on Backbone or whatever and you need to load scripts in a certain order, eg underscore.js
needs to be loaded before backbone.js
.
(说,例如,你正在构建骨干或任何一个项目,你需要加载脚本按照一定的顺序,如underscore.js
需要之前加载backbone.js
。)
How do I get it to concat the scripts so that they're in order?
(我如何获得它来连接脚本,以便它们井井有条?)
// JS concat, strip debugging and minify
gulp.task('scripts', function() {
gulp.src(['./source/js/*.js', './source/js/**/*.js'])
.pipe(concat('script.js'))
.pipe(stripDebug())
.pipe(uglify())
.pipe(gulp.dest('./build/js/'));
});
I have the right order of scripts in my source/index.html
, but since files are organized by alphabetic order, gulp will concat underscore.js
after backbone.js
, and the order of the scripts in my source/index.html
does not matter, it looks at the files in the directory.
(我在我的脚本的正确顺序source/index.html
,但由于文件是由字母顺序排列,一饮而尽将Concat的underscore.js
后backbone.js
,而在我的脚本的命令source/index.html
不问题,它会查看目录中的文件。)
So does anyone have an idea on this?
(那么有人对此有想法吗?)
Best idea I have is to rename the vendor scripts with 1
, 2
, 3
to give them the proper order, but I am not sure if I like this.
(我有最好的办法是重新命名的供应商脚本1
, 2
, 3
,给他们以正确的顺序,但我不知道如果我喜欢这个。)
As I learned more I found Browserify is a great solution, it can be a pain at first but it's great.
(当我了解到更多信息后,我发现Browserify是一个很好的解决方案,乍一看可能很麻烦,但是却很棒。)
ask by Michael Joseph Aubry translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…