3

我有一个长循环的 sass 文件(生成大约 800 行 CSS),编译大约 25 秒。它太长了。

如何最小化编译时间?

谢谢!

4

1 回答 1

2

This is how I compile Sass using gulp-sass and it takes about 800ms or less. Are you sure you use the node version, not the Ruby gulp-ruby-sass? Ruby is much slower than Node.js.

The loop may be the problem, be sure you are using Each or For, never While. But I also generated big grid system with a more less 200 selectors and it also was fast. Try my task config below:

var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var gulpif = require('gulp-if');
var minify = require('gulp-minify-css');
var argv = require('yargs').argv;
var cache = require('gulp-cached');

// Values from console flags.
var is = {
    dev: argv.develop,
    prod: argv.production
};

// Gulpfile config.
var config = {
    sass: {
        src: './src/**/*.scss',
        dest: 'src/',
        maps: '/'
    }
};


gulp.task('sass', function () {
    return gulp.src(config.sass.src)
        .pipe(cache('sass'))
        .pipe(gulpif(is.dev, sourcemaps.init()))
        .pipe(autoprefixer())
        .pipe(gulpif(is.prod, minify()))
        .pipe(gulpif(is.dev, sourcemaps.write(config.sass.maps)))
        .pipe(gulp.dest(config.sass.dest));
});
于 2015-07-28T22:02:34.913 回答