Grunt使用grunt-sass(libsass包装器),编译时间慢

bra*_*ito 5 sass gruntjs

当我运行时time sassc app.scss app.css,编译时间非常快: sassclibsass库上C实现的命令行包装器.

real    __0m0.132s__
user    0m0.123s
sys 0m0.007s
Run Code Online (Sandbox Code Playgroud)

使用时,不过grunt-sass这是Node.js包装的libsass,我里面Gruntfile.js,我得到的要慢得多的输出:

Running "watch" task
Waiting...
File "stylesheets/sass/app.scss" changed.
Running "sass:compile" (sass) task
File ./stylesheets/app.css created.

Done, without errors.
Completed in __1.759s__ at Sat May 24 2014 18:17:33 GMT+0200 (CEST) - Waiting...
Run Code Online (Sandbox Code Playgroud)

这是我的相关部分Gruntfile.js,也许我在这里做错了:

module.exports = function(grunt) {

    grunt.initConfig({

        project: {
            app: '.',
            sheets: '<%= project.app %>/stylesheets',
            sass: [ '<%= project.sheets %>/sass/app.scss',
            ],
            js: [],
        },
        // The watch task is used to run tasks in response to file changes
        watch: {
            options: {
                livereload: true,
            },
            html: {
                files: ['<%= project.app %>/*.html'],
            },
            css: {
                files: ['<%= project.sheets %>/*.css'],
            },
            sass: {
                files: '<%= project.sheets %>/sass/{,*/}*.{scss,sass}',
                tasks: ['sass:compile'],
                options: {
                    livereload: false,
                },
            },

        },
        sass: {
            compile: {
                options: {
                    style: 'nested',
                },

                files: {
                    '<%= project.sheets %>/app.css' : '<%= project.sheets %>/sass/app.scss',
                }
            }
        },

    }); // The end of grunt.initConfig

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-sass');

    grunt.registerTask('preview', ['watch', ]);
};
Run Code Online (Sandbox Code Playgroud)

为什么我在Grunt中得到如此缓慢的编译时间?

hel*_*elm 0

查看time-grunt,您应该包含它来测量 sass 任务的实际时间。

它可能与监视任务、启动时间或其他东西有关。因此,了解测量的时间来自哪里以及泄漏在哪里会很有趣。