Gulp内联源图无法正常工作

时间:2015-02-19 19:53:11

标签: sass gulp gulp-sourcemaps gulp-ruby-sass

我正在尝试让源图与Gulp一起使用。我正在使用gulp-ruby-sass和gulp-sourcemaps。

内联源图会插入到CSS文件中,但即使我启用了源图,它仍然无法在Chrome中运行。我仍然只能看到CSS文件的引用而不是sass文件。

这是我的gulpfile中的sass任务:

gulp.task('sass', function() {
    return sass('src/sass/main.scss', { sourcemap: true, style: 'expanded' }) 
    .on('error', function (err) {
        console.error('Error!', err.message);
    })
    .pipe(sourcemaps.init())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('dist/assets/css/'))
    .pipe(connect.reload());
});

我的CSS文件中的内联源图如下所示:

/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5jc3MiLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIiwic291cmNlcyI6WyJtYWluLmNzcyJdLCJzb3VyY2VzQ29udGVudCI6WyIubmF2aWdhdGlvbi1tYWluX19saXN0IHtcclxuICBkaXNwbGF5OiBpbmxpbmU7XHJcbiAgcGFkZGluZzogMDtcclxuICBtYXJnaW46IDA7XHJcbn1cclxuXHJcbi5uYXZpZ2F0aW9uLW1haW5fX2l0ZW0ge1xyXG4gIHBhZGRpbmc6IDAgMTBweDtcclxuICBsaXN0LXN0eWxlLXR5cGU6IG5vbmU7XHJcbiAgZGlzcGxheTogaW5saW5lO1xyXG59XHJcbi5uYXZpZ2F0aW9uLW1haW5fX2l0ZW06Zmlyc3Qge1xyXG4gIHBhZGRpbmctbGVmdDogMDtcclxufVxyXG4ubmF2aWdhdGlvbi1tYWluX19pdGVtOmxhc3Qge1xyXG4gIHBhZGRpbmctcmlnaHQ6IDA7XHJcbn1cclxuXHJcblxyXG4iXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= */

我将base64解码为:

{"version":3,"file":"main.css","names":[],"mappings":"","sources":["main.css"],"sourcesContent":[".navigation-main__list {\r\n  display: inline;\r\n  padding: 0;\r\n  margin: 0;\r\n}\r\n\r\n.navigation-main__item {\r\n  padding: 0 10px;\r\n  list-style-type: none;\r\n  display: inline;\r\n}\r\n.navigation-main__item:first {\r\n  padding-left: 0;\r\n}\r\n.navigation-main__item:last {\r\n  padding-right: 0;\r\n}\r\n\r\n\r\n"],"sourceRoot":"/source/"}

这看起来不错吗?我不确定它的外观是什么,但我认为scss文件名引用应该在那里?

无法让它发挥作用!

1 个答案:

答案 0 :(得分:4)

尝试删除此内容:

.pipe(sourcemaps.init())

我假设您正在使用gulp-ruby-sass的1.0.0-alpha.x版本:

https://github.com/sindresorhus/gulp-ruby-sass/tree/rw/1.0#sourcemap