繁体   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