簡體   English   中英

單個文件上的scs的Gulp Sourcemaps

[英]Gulp sourcemaps for scss on single file

sass scss/_bootstrap.scss style.css 

上面的代碼使用Sourcemaps可以正確生成,但是下面的代碼則不能

gulp.task('sass', function () {
    sass('scss/_bootstrap.scss', {sourcemap: true})
        .on('error', function (err) {
            console.error('Error!', err.message);
        })
        .pipe(sourcemaps.write())
        .pipe(debug())
        .pipe(autoprefixer())
        .pipe(gulpif(mode === 'prod', minifyCss()))
        .pipe(rename("style.css"))
        .pipe(gulp.dest(dest+'css/'));
});

有兩個問題:

  1. 你有你的無禮編譯多次變化,但您直接薩斯任務后寫的sourcemaps。 Autoprefixer和MinifyCSS會更改您的輸出,因此原始的源映射不再適用。 sourcemaps.write()調用置於管道的底部

  2. 不幸的是, gulp-minify-css有時與Sourcemaps有關。 我建議使用Sass內置的壓縮​​過程(即使通常不建議這樣做)。

該代碼將起作用:

gulp.task('sass', function () {
    return sass('bower_components/sass-bootstrap/lib/bootstrap.scss', {
            sourcemap: true,
            style: (mod === 'prod' ? 'compressed' : 'nested')
        })
        .on('error', function (err) {
            console.error('Error!', err.message);
        })
        .pipe(debug())
        .pipe(autoprefixer())
        .pipe(rename("style.css"))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('css/'));
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM