简体   繁体   English

未找到“骚扰”目标-使用Grunt时出错

[英]No 'Sass' Targets Found - Error whilst using Grunt

I've started trying to get to grips with the very basics of Grunt but when I try to run 'Grunt Sass' I get a "No 'sass' targets found" error. 我已经开始尝试了解Grunt的基本知识,但是当我尝试运行“ Grunt Sass”时,出现“未找到'sass'目标”错误。 I can't see where I'm going wrong, anyone able to give me nudge in the right direction? 我看不到我要去哪里错了,有人能向我推一下正确的方向吗?

module.exports = function(grunt) {

//configuration
grunt.initConfig({
    // pass in options to plugins, references to files
    concat: {
        js: {
            src: ['js/*.js'],
            dest: 'build/script.js'
        },
        css: {
            src: ['css/*.css'],
            dest: 'build/styles.css'
        },
        sass: {
            dist: {
                files: [{
                    src: 'css/sass/styles.scss',
                    dest: 'css/styles.css'
                        }]
                   }
               },
    }

});

//Load Plugins
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-sass');


// register tasks
grunt.registerTask('concat-js', ['concat:js']);
grunt.registerTask('concat-css', ['concat:css']);

}; };

Your sass task is nested in concat which is why it can't identify the sass task and is returning a No "sass" targets found. 您的sass任务嵌套在concat ,这就是为什么它无法识别sass任务并返回未No "sass" targets found. error. 错误。

Un-nest your sass task like such: 取消嵌套您的sass任务,例如:

grunt.initConfig({
  concat: {
    ...
  },
  sass: {
    dist: {
      files: [{
        src: 'css/sass/styles.scss',
        dest: 'css/styles.css'
      }]
    }
  },
});

Sidenote: Looks like your css task is misplaced as well, but that shouldn't affect grunt sass or grunt sass:dist from running; 旁注:看起来您的css任务也放错了位置,但这不会影响grunt sassgrunt sass:dist无法运行; however, it will not find grunt sass:css . 但是,它不会找到grunt sass:css If you want both grunt sass:css and grunt sass:dist to be available, remove the css task from js and here's how you should struct your sass task: 如果您希望grunt sass:cssgrunt sass:dist都可用,请从js删除css任务,这是sass任务的方法:

grunt.initConfig({
  concat: {
    js: {
      src: ['js/*.js'],
      dest: 'build/script.js'
    },
  },
  sass: {
    css: {
      src: ['css/*.css'],
      dest: 'build/styles.css'
    },
    dist: {
      files: [{
        src: 'css/sass/styles.scss',
        dest: 'css/styles.css'
      }]
    }
  },
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM