Change indentation in Sass

前端 未结 3 1275
北恋
北恋 2020-12-06 03:19

How can I change indentation from 2 spaces to 4 spaces in output CSS files when using Sass? I\'m using expanded style. I don\'t know anything about Ruby, but I have tried to

3条回答
  •  [愿得一人]
    2020-12-06 03:56

    Since this is the referenced question regarding sass indentation and as of now (DEC 2019), the accepted answer is outdated; I add this answer.
    According to sass documentation, amongst its options, it accepts two options called indentType and indentWidth to control indentation behavior.
    The default is using 4 spaces which can be changed to 1 tab like this:

    function css() {
        return gulp
        .src("./scss/**/*.scss")
        .pipe(plumber())
        .pipe(sass({
            outputStyle: "expanded",
            includePaths: "./node_modules",
            indentType: "tab",
            indentWidth: 1
        }))
        .on("error", sass.logError)
        .pipe(autoprefixer({
            cascade: false
        }))
        .pipe(header(banner, {
            pkg: pkg
        }))
        .pipe(gulp.dest("./css"))
        .pipe(rename({
            suffix: ".min"
        }))
        .pipe(cleanCSS())
        .pipe(gulp.dest("./css"))
        .pipe(browsersync.stream());
    }
    

提交回复
热议问题