gulp-sourcemaps with gulp-minify-css crashes

625 views Asked by At

I'm compiling bootstrap-sass with the gulp task:

gulp.task('build-bootstrap-sass', function () {
  return gulp.src('styles/styles.sass')
    .pipe(sourcemaps.init())
    .pipe(sass({includePaths: ['node_modules/bootstrap-sass/assets/stylesheets/']}).on('error', sass.logError))
    .pipe(rename({basename:'bootstrap'}))
    .pipe(autoprefixer())
    .pipe(minifyCss())
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('dist/' ));
});

But this gives me the following error:

[09:32:38] Using gulpfile d:\Code\Templates\App\gulpfile.js
[09:32:38] Starting 'build-bootstrap-sass'...
d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\text\escape-store.js:49
  var index = this.restoreMatcher.exec(placeholder)[1];
                                                   ^
TypeError: Cannot read property '1' of null
    at EscapeStore.restore (d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\text\escape-store.js:49:52)
    at UrlsProcessor.restore (d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\text\urls-processor.js:61:35)
    at Object.restore (d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\clean.js:195:28)
    at store (d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\stringifier\source-maps.js:12:21)
    at value (d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\stringifier\helpers.js:102:5)
    at property (d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\stringifier\helpers.js:91:5)
    at body (d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\stringifier\helpers.js:77:5)
    at all (d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\stringifier\helpers.js:140:9)
    at stringify (d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\stringifier\source-maps.js:74:3)
    at SelectorsOptimizer.process (d:\Code\Templates\App\node_modules\gulp-minify-css\node_modules\clean-css\lib\selectors\optimizer.js:20:10)

The issue seems to be when I use sourcemaps; If I remove it, the task passes. But I'm on the "latest" version for all my gulp dependencies; and the gulp-minify-css changelog indicates it got support for sourcemaps < 1.1.6. The build also passes when I use sourcemaps without minify.

1

There are 1 answers

0
Allan Kimmer Jensen On

gulp-sourcemaps does not support gulp-minify-css. You can find all supported plugins here: https://github.com/floridoo/gulp-sourcemaps/wiki/Plugins-with-gulp-sourcemaps-support

You could consider using gulp-cssnano for minifying css files.