Skip to content

Commit c7c0fc6

Browse files
author
ruffiem
committed
Injecting bower JS and CSS
1 parent 6b097e3 commit c7c0fc6

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

app/templates/app/index.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
<meta name="description" content="">
1111
<meta name="viewport" content="width=device-width, initial-scale=1">
1212

13-
<!-- bower:css -->
14-
<!-- endbower -->
15-
1613
<!-- inject:css -->
1714
<!-- endinject -->
1815

@@ -21,9 +18,6 @@
2118

2219
<app>Loading...</app>
2320

24-
<!-- bower:js -->
25-
<!-- endbower -->
26-
2721
<!-- inject:js -->
2822
<!-- endinject -->
2923

app/templates/gulpfile.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ var PATH = {
5353
dev: {
5454
all: 'dist/dev',
5555
lib: 'dist/dev/lib',
56+
vendor: 'dist/dev/vendor',
5657
ng2: 'dist/dev/lib/angular2.js',
5758
router: 'dist/dev/lib/router.js'
5859
},
5960
prod: {
6061
all: 'dist/prod',
61-
lib: 'dist/prod/lib'
62+
lib: 'dist/prod/lib',
63+
vendor: 'dist/prod/vendor'
6264
}
6365
},
6466
src: {
@@ -198,9 +200,9 @@ gulp.task('build.assets.dev', [
198200

199201
gulp.task('build.index.dev', function () {
200202
var target = gulp.src(injectableDevAssetsRef(), {read: false});
203+
var bower = injectableBowerComponents('dev');
201204
return gulp.src(PATH.dest.dev.all + '/index.html')
202-
.pipe(inject(target, {transform: transformPath('dev')}))
203-
.pipe(inject(addBowerComponent(PATH.dest.dev.lib), {name: 'bower', relative: true}))
205+
.pipe(inject(series(target, bower), { transform: transformPath('dev') }))
204206
.pipe(template(templateLocals()))
205207
.pipe(gulp.dest(PATH.dest.dev.all));
206208
});
@@ -304,11 +306,11 @@ gulp.task('build.assets.prod', [
304306
});
305307

306308
gulp.task('build.index.prod', function () {
309+
var bower = injectableBowerComponents('prod');
307310
var target = gulp.src([join(PATH.dest.prod.lib, 'lib.js'),
308311
join(PATH.dest.prod.all, '**/*.css')], {read: false});
309312
return gulp.src(PATH.dest.prod.all + '/index.html')
310-
.pipe(inject(target, {transform: transformPath('prod')}))
311-
.pipe(inject(addBowerComponent(PATH.dest.prod.lib), {name: 'bower', relative: true}))
313+
.pipe(inject(series(target, bower), { transform: transformPath('prod') }))
312314
.pipe(template(templateLocals()))
313315
.pipe(gulp.dest(PATH.dest.prod.all));
314316
});
@@ -429,28 +431,21 @@ function registerBumpTasks() {
429431
});
430432
}
431433

432-
function addBowerComponent(path) {
433-
var jsFilter = filter('*.js');
434-
var cssFilter = filter('*.css');
434+
function injectableBowerComponents(path) {
435+
436+
var jsFilter = filter('**/*.js');
437+
var cssFilter = filter('**/*.css');
438+
435439
return gulp.src(bowerFiles())
436-
.pipe(jsFilter)
437-
.pipe(concat('vendors.js'))
438-
.pipe(gulp.dest(path))
439-
.pipe(uglify())
440-
.pipe(rename({
441-
suffix: '.min'
442-
}))
443-
.pipe(gulp.dest(path))
444-
.pipe(jsFilter.restore())
445-
.pipe(cssFilter)
446-
.pipe(concat('vendors.css'))
447-
.pipe(gulp.dest(path))
448-
.pipe(minifyCSS({keepBreaks:true}))
449-
.pipe(rename({
450-
suffix: '.min'
451-
}))
452-
.pipe(gulp.dest(path))
453-
.pipe(cssFilter.restore())
440+
.pipe(jsFilter)
441+
.pipe(uglify())
442+
.pipe(gulp.dest(PATH.dest[path].vendor))
443+
.pipe(jsFilter.restore())
444+
.pipe(cssFilter)
445+
.pipe(concat('vendor.css'))
446+
.pipe(minifyCSS())
447+
.pipe(gulp.dest(PATH.dest[path].vendor))
448+
.pipe(cssFilter.restore());
454449
}
455450

456451
function serveSPA(env) {

0 commit comments

Comments
 (0)