简体   繁体   English

单个文件上的scs的Gulp Sourcemaps

[英]Gulp sourcemaps for scss on single file

sass scss/_bootstrap.scss style.css 

Above code generates properly with sourcemaps but not the below code 上面的代码使用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/'));
});

There are two issues: 有两个问题:

  1. You have multiple changes after your Sass compilation, but you write the sourcemaps directly after your Sass task. 你有你的无礼编译多次变化,但您直接萨斯任务后写的sourcemaps。 Autoprefixer and MinifyCSS change your output, so the original sourcemaps are not true anymore. Autoprefixer和MinifyCSS会更改您的输出,因此原始的源映射不再适用。 Put the sourcemaps.write() call to the bottom of your pipe sourcemaps.write()调用置于管道的底部

  2. Unfortunately, gulp-minify-css sometimes has issues with Sourcemaps. 不幸的是, gulp-minify-css有时与Sourcemaps有关。 I'd suggest to use the built-in compression process from Sass (even though it's not usually recommended. 我建议使用Sass内置的压缩​​过程(即使通常不建议这样做)。

This code will work: 该代码将起作用:

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