Grunt没有执行grunt-contrib-sass任务

时间:2014-03-12 15:50:36

标签: javascript ruby node.js sass gruntjs

我已使用 grunt-contrib-sass 插件将Sass任务添加到我的grunt进程中。这是我的gruntfile:

module.exports = function ( grunt ) {
    grunt.loadNpmTasks('grunt-contrib-sass');

    /**
     * Load in our build configuration file.
     */
    var userConfig = require( './build.config.js' );

    /**
     * This is the configuration object Grunt uses to give each plugin its
     * instructions.
     */
    var taskConfig = {
        /**
         * We read in our `package.json` file so we can access the package name and
         * version. It's already there, so we don't repeat ourselves here.
         */
        pkg: grunt.file.readJSON("package.json"),
        sass: {
            dev: {
                files: [{
                    expand: true,
                    cwd: 'css',
                    src: ['**/*.scss'],
                    dest: 'css',
                    ext: '.css'
                }]
            },
            prod: {
                files: [{
                    expand: false,
                    cwd: 'css',
                    src: ['**/*.scss'],
                    dest: 'css',
                    ext: '.css'
                }]
            }
        },
    };
    grunt.initConfig( grunt.util._.extend( taskConfig, userConfig ) );

    grunt.registerTask('default', [ 'sass:prod' ]);
    grunt.registerTask('dev-build', [ 'sass']);
    grunt.registerTask('sass', [ 'sass:dev' ]);

    grunt.event.on('watch', function(action, filepath, target) {
        grunt.log.writeln(target + ': ' + filepath + ' has ' + action);
    });
};

我安装了Ruby 1.9.3和Sass Gem 3.3.2并在命令行和IntelliJ 13上工作。但是当我尝试运行 grunt sass 或对我的scss应用grunt watch时文件,我得到以下跟踪输出:

<c:\users\[proj_dir_path]>grunt sass --verbose
Initializing
Command-line options: --verbose

Reading "gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.

Registering "grunt-contrib-sass" local Npm module tasks.
Reading C:\Users\[proj_path]\node_modules\grunt-contrib-sass\package.json...OK
Parsing C:\Users\[proj_path]\node_modules\grunt-contrib-sass\package.json...OK
Loading "sass.js" tasks...OK
+ sass
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Loading "gruntfile.js" tasks...OK
+ sass

Running tasks: sass

Running "sass" task

[About 500 more repeats of this]

Running "sass" task
Warning: Maximum call stack size exceeded Use --force to continue.

Aborted due to warnings.

要运行SCSS Gem,我必须使用参数执行scss.bat命令。我最好的猜测是Grunt Sass插件尝试使用参数执行Ruby EXE,而在我的系统上我必须使用bat来运行它。这只是我猜测梳理sass.js任务代码。有没有其他人有类似的问题,是否有任何解决方法或解决此问题?

2 个答案:

答案 0 :(得分:4)

我认为这是一个递归问题,注册的任务在循环中运行。

我的作品没有

  

grunt.registerTask(&#39; sass&#39;,[&#39; sass:dev&#39;]);

因为它看起来在initConfig中设置的任何内容都自动成为一项任务。如果删除该行并不起作用,请尝试重命名

  

grunt.registerTask(&#39; my-sass&#39;,[&#39; sass:dev&#39;]);

并正在运行

  

grunt my-sass

答案 1 :(得分:0)

尝试更改 -

grunt.registerTask('sass', [ 'sass' ]);

grunt.registerTask('sass', [ 'sass:dev' ]);

grunt.registerTask('sass', [ 'sass:prod' ]);