I would like to remove all the comments from the CSS code but I have noticed that when I added gulp-strip-css-comments to my gulp task the sourcemap no longer works, even when I'm making sure that gulp-strip-css-comments keeps the comment that points to the source map /*# sourceMappingURL=style.css.map */
by using the regular expression option.
Below I have added my code and output before and after using gulp-strip-css-comments:
Before gulp-strip-css-comments
gulp.task('sass:dev', function () {
gulp.src('./sass/*.scss')
.pipe(sourcemaps.init())
.pipe(
sass({
includePaths: [
'./node_modules/breakpoint-sass/stylesheets/'
]
})
.on('error', sass.logError)
)
.pipe(autoprefixer({
browsers: ['last 2 version', 'ie 11']
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./css'));
});
After gulp-strip-css-comments
gulp.task('sass:dev', function () {
gulp.src('./sass/*.scss')
.pipe(sourcemaps.init())
.pipe(
sass({
includePaths: [
'./node_modules/breakpoint-sass/stylesheets/'
]
})
.on('error', sass.logError)
)
.pipe(autoprefixer({
browsers: ['last 2 version', 'ie 11']
}))
.pipe(sourcemaps.write('.'))
.pipe(stripCssComments({preserve: /^# sourceMappingURL=/}))
.pipe(gulp.dest('./css'));
});