How to ignore some part of the path using wiredep and gulp

2.2k Views Asked by At

I am creating Gulp task that will inject js and css using wiredep. below is how it is getting injected.

<!-- inject:js -->
<script src="/src/config/app.js"></script>
<!-- endinject -->

but I need to inject

<!-- inject:js -->
<script src="config/app.js"></script>
<!-- endinject -->

How do I Ignore '/src/'?

This is what I have tried and didn't work.

Gulp task is below

gulp.task('wiredep', ['styles'], function(){
    var options = {
        bowerJson: require('./bower.json'),
        directory:  './bower_components/',
        ignorePath: './src/'
        };
    var wiredep = require('wiredep').stream;
    return gulp
        .src(config.index)
        .pipe(wiredep(options))
        .pipe($.inject(gulp.src('./src/**/*.js')))
        .pipe(gulp.dest(config.dist));
});

Thanks, Kashyap

3

There are 3 best solutions below

0
keithl8041 On

You don't say what result you're getting so it's difficult to troubleshoot, but all you have to do is match the path exactly (unless you want to use regex), so in your case this should do the trick;

ignorePath: '/src/'
0
捌莱闲人 On

Wiredep is used to inject bower dependance into html, and i see you must want to inject the general js file, maybe it can work fine below:

gulp.task('inject', ['styles'], function(){
  var options = {
    ignorePath: 'src/',
    addRootSlash: false
  };
  return gulp
    .src(config.index)
    .pipe($.inject(gulp.src('./src/**/*.js'), options))
    .pipe(gulp.dest(config.dist));
});

Hoping this helps.

0
redflasher On

You can exclude folders:

var options = {
...
exclude: [/\/src/],
...
};