如何将gulp use ref与sass一起使用

如何将gulp use ref与sass一起使用,sass,gulp,gulp-useref,Sass,Gulp,Gulp Useref,在该项目中,我有: <!-- build:css css/error.css --> <link rel="stylesheet" href="src/assets/styles/_bootstrap.scss" type="text/css" media="all"> <!-- endbuild --> 如何首先将.scss转换为.css,然后使用use-ref.在我的项目中,我使用gulp rename来做类似的事情 .pipe(rename({ suf

在该项目中,我有:

<!-- build:css css/error.css -->
<link rel="stylesheet" href="src/assets/styles/_bootstrap.scss" type="text/css" media="all">
<!-- endbuild -->

如何首先将.scss转换为.css,然后使用use-ref.

在我的项目中,我使用
gulp rename
来做类似的事情

.pipe(rename({ suffix: '.min' }))
安装

在您的任务中,请执行以下操作:

gulp.task('test', function () {
    return gulp.src('path_to_html')
        .pipe(gulp.src('path_to_styles'))
        .pipe(gulpif('path_to_styles', sass()))
        .pipe('path_to_styles'.restore())
        .pipe(rename({
            extname: ".css"
        }))
        .pipe(useref())
        .pipe(gulp.dest('target_folder'));
});

由于sass编译为单个css文件,因此我在html中只引用了sass输出css文件,而没有对该文件使用inject
gulp.task('test', function () {
    return gulp.src('path_to_html')
        .pipe(gulp.src('path_to_styles'))
        .pipe(gulpif('path_to_styles', sass()))
        .pipe('path_to_styles'.restore())
        .pipe(rename({
            extname: ".css"
        }))
        .pipe(useref())
        .pipe(gulp.dest('target_folder'));
});