Skip to content

Commit c0d5a14

Browse files
committed
fix(gulp): inject angular modules before other scripts
add sort function to ensure angular modules appear first in inject:js task
1 parent 20460a5 commit c0d5a14

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Diff for: app/templates/gulpfile.babel(gulp).js

+20-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ function whenServerReady(cb) {
9191
100);
9292
}
9393

94+
function sortModulesFirst(a, b) {
95+
var module = /\.module\.js$/;
96+
var aMod = module.test(a.path);
97+
var bMod = module.test(b.path);
98+
// inject *.module.js first
99+
if (aMod === bMod) {
100+
// either both modules or both non-modules, so just sort normally
101+
if (a.path < b.path) {
102+
return -1;
103+
}
104+
if (a.path > b.path) {
105+
return 1;
106+
}
107+
return 0;
108+
} else {
109+
return (aMod ? -1 : 1);
110+
}
111+
}
112+
94113
/********************
95114
* Reusable pipelines
96115
********************/
@@ -164,7 +183,7 @@ gulp.task('inject:js', () => {
164183
return gulp.src(paths.client.mainView)
165184
.pipe(plugins.inject(
166185
gulp.src(_.union(paths.client.scripts, ['!client/**/*.spec.<%= scriptExt %>']), {read: false})
167-
.pipe(plugins.sort()),
186+
.pipe(plugins.sort(sortModulesFirst)),
168187
{
169188
starttag: '<!-- injector:js -->',
170189
endtag: '<!-- endinjector -->',

0 commit comments

Comments
 (0)