简体   繁体   English

gulp useref适用于Bower组件,但不适用于我的应用程序文件(css和js)

[英]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: 运行构建任务时,useref不能达到我的预期:

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: 所以在我的gruntfile中,我有一个任务:

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 运行我的任务时,它会创建一个lib.js文件和一个assets / styles / lib.css文件,但不会生成project.js,也不会创建资产/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... 我的js文件是用typescript编写的,并且经过了整理和成功创建,并且css来自sass,我很确定它们中没有错误,因此它一定是其他东西。

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 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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