Skip to content Skip to sidebar Skip to footer

How To Add Specific Bower Components As Ie8 Conditional Block In Gulp

I have several bower components, of which I need some components like json3, respondjs, es5shim to be added in an IE8 conditional block (in build as well as serve) like this : <

Solution 1:

It is possible with gulp-filter and gulp-inject's starttag option.

Suppose you have the following injections defined in index.html:

<!--[if lt IE 9]>
<![endif]--><!-- inject:js --><!-- endinject -->

You can wire them in gulpfile:

var gulp = require('gulp')
var bowerFiles = require('main-bower-files');
var gulpFilter = require('gulp-filter');
var gulpInject = require('gulp-inject');

gulp.task('wiredep', function() {
    var ie8Files = ['**/json3.js', '**/es5shim.js'];
    // the same as: var restFiles = ['*', '!**/json3.js', '!**/es5shim.js'];var restFiles = ['*'].concat(ie8Files.map(function(e) { return'!' + e;}));
    return gulp.src('index.html')
    .pipe(gulpInject(gulp.src(bowerFiles(), {read: false}).pipe(gulpFilter(restFiles))))
    .pipe(gulpInject(gulp.src(bowerFiles(), {read: false}).pipe(gulpFilter(ie8Files)),
                    {starttag: '<!--[if lt IE 9]>', endtag: '<![endif]-->'}))
    .pipe(gulp.dest('dist'));
});

Which results in (for example):

<!--[if lt IE 9]>
<script src="bower_components/json3/json3.js"></script>
<script src="bower_components/shim/es5shim.js"></script>
<![endif]--><!-- inject:js --><scriptsrc="bower_components/jquery/jquery.js"></script><!-- endinject -->

Post a Comment for "How To Add Specific Bower Components As Ie8 Conditional Block In Gulp"