【问题标题】:Grunt not executing grunt-contrib-sass taskGrunt 未执行 grunt-contrib-sass 任务
【发布时间】:2014-04-16 21:36:09
【问题描述】:

我已使用 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 或将 grunt watch 应用到我的 scss 时文件,我得到以下跟踪输出:

<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 任务代码的猜测。有没有其他人遇到过类似的问题,是否有任何解决方法或解决方案?

【问题讨论】:

    标签: javascript ruby node.js sass gruntjs


    【解决方案1】:

    尝试改变 -

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

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

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

    【讨论】:

    • 谢谢。看起来像是一个明显的失误,但仍然产生相同的结果。
    【解决方案2】:

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

    我的作品没有

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

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

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

    并运行

    咕噜咕噜

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-06
      • 2017-10-15
      • 2023-03-12
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多