简体   繁体   中英

SCSS, Compass and GULP: How to minify without breaking CSS?

I am using Gulp-Compass and want to minify my CSS.

When I do this, the following code

.tags-bar .sub-bullet:nth-last-of-type {
display:none; 
}

.ux-panel-hidden{
display:none;
}

becomes minified to:

.tags-bar .sub-bullet:nth-last-of-type,.ux-panel-hidden{display:none}

The :nth-type part confuses the browser, so the ux-panel-hidden doesn't get read.

JSFiddle with minified code

JSfildde with non-minified code

tags-bar and ux-panel are in separate _scss files, so I am not sure why the minfication brings them together.

How can I fix it?

Here is my Gulp Code:

gulp.task('compass', function() {
    return gulp.src('frontend/build/css/*.scss')
        .pipe(compass({
            css: 'frontend/dist/css',
            sass: 'frontend/build/css',
            image: 'frontend/images/',
            font: 'stylesheets/fonts',
            require: ['susy', 'breakpoint'],
            bundle_exec: true
        }))
        .pipe(plumber({
            errorHandler: onError
        }))
        .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
        .pipe(gulp.dest('frontend/dist/css'))
        .pipe(rename({
         suffix: '.min'
        }))
        .pipe(minifycss())
        .pipe(gulp.dest('frontend/dist/css'))
        .pipe(notify({ // Add gulpif here
            sound: "Pop"
        }));
});

:nth-last-of-type is not valid syntax since it requires an argument to be passed eg. :nth-last-of-type(odd)

This may be causing your issue.

More reading on the property at CSS-Tricks https://css-tricks.com/almanac/selectors/n/nth-last-of-type/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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