简体   繁体   English

将gulp-sourcemap与gulp-csso和gulp-sass结合

[英]Combining gulp-sourcemaps with gulp-csso and gulp-sass

I'm trying to get this part of my gulpfile.js to work: 我正在尝试使gulpfile.js这一部分正常工作:

gulp.task('compileSass', function() {
    return gulp.src(folders.src+'/scss/*scss')
    .pipe(sass())
    .pipe(gulp.dest(folders.dest+'/css'));
});

gulp.task('minifyStyles', ['compileSass'], function() {
    return gulp.src(folders.dest+'/css/style.css')
    .pipe(maps.init())
    .pipe(minCss({
        sourceMap: true
    }))
    .pipe(maps.write('./'))
    .pipe(rename('style.min.css'))
    .pipe(gulp.dest(folders.dest+'/css'));
});

I'd like dev tools to show the .scss files. 我想要开发工具来显示.scss文件。 I'm not sure if it has to do with the rename() or if I'm calling my sourcemaps at the wrong time, but when I check the dev tools, the source is always style.min.css . 我不确定这是否与named rename()或者我是否在错误的时间调用了源地图,但是当我检查开发工具时,源始终是style.min.css

I don't see an initial mapping on your sass task. 我看不到您的sass任务的初始映射。 You need to call this twice, and set loadMaps appropriately per the docs . 您需要调用两次,并根据docs适当设置loadMaps Try the following... 尝试以下...

gulp.task('compileSass', function() {
  return gulp.src(folders.src+'/scss/*scss')
  .pipe(maps.init()) /* `init` here */
  .pipe(sass())
  .pipe(gulp.dest(folders.dest+'/css'));
});

gulp.task('minifyStyles', ['compileSass'], function() {
  return gulp.src(folders.dest+'/css/style.css')
  .pipe(maps.init({
    loadMaps: true /* `init` again, load prior from sass */
  }))
  .pipe(minCss({
    sourceMap: true
  }))
  .pipe(maps.write('./'))
  .pipe(rename('style.min.css'))
  .pipe(gulp.dest(folders.dest+'/css'));
});

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

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