简体   繁体   中英

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

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...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM