Grunt - 找不到任务默认值和语法错误

时间:2014-10-10 21:46:21

标签: gruntjs

我需要一些帮助来找到错误,请你:(
我不知道发生了什么,我无法找到错误大声笑。

我不知道还有什么要写在这里,因为stackoverflow不允许我提交我的问题,我很生气,我的上帝。

图像: https://docs.google.com/file/d/0B-A93ehYLxVKN2lEWkJwbGRIWHM/edit?usp=drivesdk

module.exports = function( grunt ) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),


uglify : {
    options : {
        mangle : false
},
my_target : {
    files : {
        'assets/js/main.js' : [ 'source/js/scripts.js' ]
    }
}
}, // uglify


sass : {
    dist : {
        files : {
            'assets/css/style.css' : 'source/sass/style.sass'
        }
    }
},  // sass


cssmin: {
    my_target: {
        files: [{
            expand: true,
            cwd: 'source/css/',
            src: ['*.css', '!*.min.css'],
            dest: 'assets/css/',
            ext: '.min.css'
        }]
    }
},  // cssmin


browserSync: {
    default_options: {
    bsFiles: {
            src: [
                "source/css/*.css",
                "source/js/custom/*.js",
                "*.html"
                ]
        },
        options: {
            watchTask: true,
            server:{
            baseDir: "./"
        }
        }
    }
}, // sync

watch: {
    css: {
        files: '**/*.sass',
        tasks: ['sass'],
    options: {
        livereload: true,
        },
    },
    javascript:{
        files: "source/js/*.js",
        tasks: [
            "uglify"
        ]
    }
  } // watch

  grunt.loadNpmTasks( 'grunt-contrib-uglify' );
  grunt.loadNpmTasks( 'grunt-contrib-sass' );
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-browser-sync');
  grunt.loadNpmTasks('grunt-contrib-watch');

  // default

  grunt.registerTask( 'default', [ 'uglify', 'sass','cssmin','browserSync' ,'watch'] );

  });
};

1 个答案:

答案 0 :(得分:3)

看起来})的结束grunt.initConfig位于错误的位置。它应该在grunt.loadNpmTasks来电之前。

module.exports = function( grunt ) {
grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),
  uglify : {
    options : {
      mangle : false
  },
  my_target : {
    files : {
      'assets/js/main.js' : [ 'source/js/scripts.js' ]
      }
    }
  }, // uglify
  sass : {
    dist : {
      files : {
        'assets/css/style.css' : 'source/sass/style.sass'
      }
    }
  },  // sass
  cssmin: {
    my_target: {
      files: [{
        expand: true,
        cwd: 'source/css/',       
        src: ['*.css', '!*.min.css'],
        dest: 'assets/css/',      
        ext: '.min.css'           
      }]                        
    }                  
  },  // cssmin
  browserSync: {
    default_options: {
      bsFiles: {                    
        src: [                                 
          "source/css/*.css",                    
          "source/js/custom/*.js",             
          "*.html"                             
        ]                                        
      },                                     
      options: {                    
        watchTask: true,                       
        server: {                              
          baseDir: "./"                          
        }                                      
      }                                      
    }                             
  }, // sync   
  watch: {
    css: { 
      files: '**/*.sass',
      tasks: ['sass'],        
    options: {                
      livereload: true,
      },
    },
    javascript:{
        files: "source/js/*.js",
        tasks: [
            "uglify"
        ]
    }
  } // watch
});

grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-contrib-sass' );
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-browser-sync');
grunt.loadNpmTasks('grunt-contrib-watch');

// default
grunt.registerTask( 'default', [ 'uglify', 'sass','cssmin','browserSync' ,'watch'] );
};