简体   繁体   English

gulp-clean-css,gulp-ruby-sass和gulp-sourcemaps之间不兼容

[英]incompatibility between gulp-clean-css, gulp-ruby-sass and gulp-sourcemaps

I have this task defined in my gulpfile.js: 我在gulpfile.js中定义了以下任务:

var sass     = require('gulp-ruby-sass');
var cleanCss = require('gulp-clean-css');
var srcmaps  = require('gulp-sourcemaps');

gulp.task('css',function(){
    return  sass('css/**/*.scss',{sourcemap: true})
            .on('error',sass.logError)
            .pipe(srcmaps.write())
            .pipe(cleanCss())
            .pipe(gulp.dest('css'));
});

The final output it's right, except for the fact that the source map generated doesn't seem to work (tested in firefox, the inspector always points to line 1, since the css is minified). 最终输出是正确的,除了生成的源映射似乎不起作用的事实(在firefox中测试,检查器始终指向第1行,因为css最小化)。

I tried adding pipe(srcmaps.init()) before pipe(cleanCss) but it didn't work either. 我试着在pipe(cleanCss)之前添加pipe(srcmaps.init()) ,但是它也不起作用。 Removing the cleanCss line solved the problem (The source map worked fine), but the css won't get minified. 删除cleanCss行解决了该问题(源映射工作正常),但不会缩小CSS。

What am I missing? 我想念什么?

Update: The cleanCss debug output is the following: 更新:cleanCss调试输出如下:

liquidacion.css: 7797
liquidacion.css: 1200
baja_cajas.css: 9918
baja_cajas.css: 2071
caja.css: 13160
caja.css: 2605
main.css: 11935
main.css: 2394
posiciones.css: 12905
posiciones.css: 2625
solicitud.css: 16182
solicitud.css: 3305
traslados.css: 12047
traslados.css: 2646
empleo.css: 19207
empleo.css: 3816
ingresos.css: 13832
ingresos.css: 2985
rq_personal.css: 17155
rq_personal.css: 3882

I already tried adding srcmaps.init() before cleanCss (and after sass), but it didn't work either. 我已经尝试在cleanCss之前(和sass之后)添加srcmaps.init(),但是它也不起作用。

gulp-sourcemaps only records transformations to your CSS up until srcmaps.write() . gulp-sourcemaps只会记录到CSS的转换,直到srcmaps.write()为止。 Once srcmaps.write() is called the source maps are written to the stream and any subsequent transformations will not be reflected in your source maps. 调用srcmaps.write() ,会将源映射写入流,并且任何后续转换都不会反映在您的源映射中。

That means you need to run cleanCss() before srcmaps.write() if you want the minification to be reflected in your source maps: 这意味着你需要运行cleanCss()之前srcmaps.write()如果你想缩小到反映在源地图:

gulp.task('css',function(){
  return  sass('css/**/*.scss',{sourcemap: true})
        .on('error',sass.logError)
        .pipe(cleanCss())
        .pipe(srcmaps.write())
        .pipe(gulp.dest('css'));
});

因此,我最终以gulp-sass代替gulp-ruby-sass,一切都按预期进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM