gulp useref working for bower components, but not for my app files (css and js)

514 views Asked by At

When running my build task, useref doesn't do what I expected:

in my index I have:

<!-- build:css /assets/styles/lib.css -->
<!-- bower:css -->
    <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css" />
<!-- endbower -->
<!-- endbuild -->

<!-- build:css /assets/styles/main.css -->
<!-- inject:css -->
    <link rel="stylesheet" href="assets/styles/main.css">
<!-- endinject -->
<!-- endbuild -->

<!-- build:js /lib.js -->
<!-- bower:js -->
    <script src="/bower_components/jquery/dist/jquery.js"></script>
    <script src="/bower_components/angular/angular.js"></script>
<!-- endbower -->
<!-- endbuild -->

<!-- build:js ./project.js -->
<!-- inject:js -->
    <script src="app.js"></script>
<!-- endinject -->
<!-- endbuild -->

so in my gruntfile i have a task:

gulp.task('build-optimise', function () {
    log('Optimising project');
    return gulp.src(config.app + 'index.html')
        .pipe($.useref({searchPath: ['./bower_components', config.app]}))
        .pipe($.print())
        .pipe($.if('*.js', $.uglify({
            mangle: false
        })))
        .pipe($.if('*.css', $.minifyCss()))
        .pipe(gulp.dest(config.dist));
}); // config.app = ./local which contains my local build

when running my task, it makes a lib.js file and a assets/styles/lib.css file, but no project.js and no assets/styles/main.css

How can I fix this? the js files of me are written with typescript and have been linted and succesfully created and css comes from sass and I'm pretty sure they have no errors in them, so it must be something else...

1

There are 1 answers

0
rick On

I'm doing something similar in my project

my gulp task adapted to your situation is like this

gulp.task('build-optimise', function () {
    log('Optimising project');
    return gulp.src(config.app + 'index.html')
        .pipe($.useref())
        .pipe($.if('*.js', $.uglify()))
        .pipe($.if('*.css', $.minifyCss()))
        .pipe(gulp.dest(config.dis));
 });

hope this helps