Gruntjs Grunt-致命错误:数据不足

Gruntjs Grunt-致命错误:数据不足,gruntjs,grunt-contrib-watch,grunt-spritesmith,Gruntjs,Grunt Contrib Watch,Grunt Spritesmith,在使用spritesmith处理图像时,我的GrunFile上出现了一个奇怪的。。有人见过这个吗 这是我的文件。。没有什么太大的问题,但当涉及到精灵一代。。。我猜这是个记忆问题 module.exports = function(grunt) { var globalConfig = { siteName: 'mysite', }; grunt.initConfig({ pkg: grunt.file.readJSON('package.json'),

在使用spritesmith处理图像时,我的GrunFile上出现了一个奇怪的。。有人见过这个吗

这是我的文件。。没有什么太大的问题,但当涉及到精灵一代。。。我猜这是个记忆问题

    module.exports = function(grunt) {

    var globalConfig = { siteName: 'mysite', };

    grunt.initConfig({

    pkg: grunt.file.readJSON('package.json'),

    globalConfig: globalConfig, // my variables inititalized here

    /* WATCH Configuration */

    watch: {
      js: {
        files: ['wp-content/themes/<%= globalConfig.siteName %>/assets/libs/js/plugins/**/*.js','wp-content/themes/<%= globalConfig.siteName %>/assets/js/app.js'],
        tasks: ['concat:dist', 'uglify:dist'],
      },
      sprite: {
        files: ['wp-content/themes/<%= globalConfig.siteName %>/assets/libs/sprite/*.png'],
        tasks: ['sprite:dist'],
      },  
      sass: {
        files: ['wp-content/themes/<%= globalConfig.siteName %>/assets/css/**/*.scss'],
        tasks: ['sass:dist']
      },
      livereload: {
        files: [
          'wp-content/themes/<%= globalConfig.siteName %>/*.html',
          'wp-content/themes/<%= globalConfig.siteName %>/*.php',
          'wp-content/themes/<%= globalConfig.siteName %>/partials/*.php',
          'wp-content/themes/<%= globalConfig.siteName %>/functions/*.php',                                         
          'wp-content/themes/<%= globalConfig.siteName %>/assets/js/*.{js,json}',
          'wp-content/themes/<%= globalConfig.siteName %>/assets/css/**/*.{scss,css}',
          'wp-content/themes/<%= globalConfig.siteName %>/assets/images/*.{png,jpg,jpeg,gif,webp,svg}'
        ],
        options: {
          livereload: true
        }
      }
    },

    /* SASS Configuration */
    sass: { 
      options: {
        sourceMap: true,
        outputStyle: 'compressed',
      },
      dist: {
        files: {
          'wp-content/themes/<%= globalConfig.siteName %>/style.css': 'wp-content/themes/<%= globalConfig.siteName %>/assets/css/main.scss'
        }
      }
    },

    /* UGLIFY Configuration */
    uglify: {
      options: {
        mangle: false
      },
      dist: {
        files: {
          'wp-content/themes/<%= globalConfig.siteName %>/assets/js/production.min.js': ['wp-content/themes/<%= globalConfig.siteName %>/assets/js/production.js']
        }
      }
    },

    /* CONCAT Configuration */
    concat: {
      options: {
        separator: ';',
      },
      dist: {
        src: [
          'wp-content/themes/<%= globalConfig.siteName %>/assets/libs/js/plugins/modernizr.js',
          'wp-content/themes/<%= globalConfig.siteName %>/assets/libs/js/plugins/html5shiv.js',
          'wp-content/themes/<%= globalConfig.siteName %>/assets/libs/js/plugins/jquery.fancybox.js',
          'wp-content/themes/<%= globalConfig.siteName %>/assets/libs/js/plugins/jquery.fancybox-media.js',
          'wp-content/themes/<%= globalConfig.siteName %>/assets/libs/js/plugins/slick.js',
          'wp-content/themes/<%= globalConfig.siteName %>/assets/libs/js/plugins/jquery.mixitup.js',
          'wp-content/themes/<%= globalConfig.siteName %>/assets/js/app.js'
        ],
        dest: 'wp-content/themes/<%= globalConfig.siteName %>/assets/js/production.js',
      },
    },




    sprite:{
      dist: {
        src:     'wp-content/themes/<%= globalConfig.siteName %>/assets/libs/sprite/*.png',
        dest:    'wp-content/themes/<%= globalConfig.siteName %>/assets/sprite.png',
        destCss: 'wp-content/themes/<%= globalConfig.siteName %>/assets/sprite.css'
      }
    }






      });




      grunt.loadNpmTasks('grunt-sass');
      grunt.loadNpmTasks('grunt-contrib-watch');
      grunt.loadNpmTasks('grunt-contrib-uglify');
      grunt.loadNpmTasks('grunt-contrib-concat');
      grunt.loadNpmTasks('grunt-spritesmith');

      grunt.registerTask('default', ['sass:dist', 'concat:dist', 'uglify:dist','sprite:dist', 'watch'] );
      // grunt.registerTask('dev-watch', ['concat:dist', 'uglify']);

    };
module.exports=函数(grunt){
var globalConfig={siteName:'mysite',};
grunt.initConfig({
pkg:grunt.file.readJSON('package.json'),
globalConfig:globalConfig,//my variables inititalized here
/*手表配置*/
观察:{
js:{
文件:['wp-content/themes//assets/libs/js/plugins/***.js','wp-content/themes//assets/js/app.js'],
任务:['concat:dist','uglify:dist'],
},
雪碧:{
文件:['wp-content/themes//assets/libs/sprite/*.png'],
任务:['sprite:dist'],
},  
sass:{
文件:['wp-content/themes//assets/css/***.scss'],
任务:['sass:dist']
},
利弗雷罗德:{
档案:[
“wp content/themes/*.html”,
“wp content/themes/*.php”,
'wp content/themes//partials/*.php',
'wp content/themes//functions/*.php',
“wp content/themes//assets/js/.{js,json}”,
“wp content/themes//assets/css/***.{scss,css}”,
'wp content/themes//assets/images/.{png、jpg、jpeg、gif、webp、svg}'
],
选项:{
利弗雷罗德:没错
}
}
},
/*SASS配置*/
萨斯:{
选项:{
sourceMap:true,
outputStyle:'压缩',
},
地区:{
档案:{
“wp-content/themes//style.css”:“wp-content/themes//assets/css/main.scss”
}
}
},
/*丑陋的外形*/
丑陋的:{
选项:{
马槽:错
},
地区:{
档案:{
'wp-content/themes//assets/js/production.min.js':['wp-content/themes//assets/js/production.js']
}
}
},
/*CONCAT配置*/
康卡特:{
选项:{
分隔符:';',
},
地区:{
src:[
“wp content/themes//assets/libs/js/plugins/modernizer.js”,
“wp content/themes//assets/libs/js/plugins/html5shiv.js”,
'wp content/themes//assets/libs/js/plugins/jquery.fancybox.js',
'wp content/themes//assets/libs/js/plugins/jquery.fancybox media.js',
“wp content/themes//assets/libs/js/plugins/slick.js”,
'wp content/themes//assets/libs/js/plugins/jquery.mixitup.js',
'wp content/themes//assets/js/app.js'
],
dest:'wp content/themes//assets/js/production.js',
},
},
雪碧:{
地区:{
src:'wp content/themes//assets/libs/sprite/*.png',
dest:'wp content/themes//assets/sprite.png',
destCss:'wp content/themes//assets/sprite.css'
}
}
});
grunt.loadNpmTasks(“grunt-sass”);
grunt.loadNpmTasks(“grunt-contrib-watch”);
grunt.loadNpmTasks(“grunt-contrib-uglify”);
grunt.loadNpmTasks(“grunt-contrib-concat”);
grunt.loadNpmTasks(“grunt-spritesmith”);
registerTask('default',['sass:dist','concat:dist','uglify:dist','sprite:dist','watch']);
//grunt.registerTask('dev-watch',['concat:dist','uglify']);
};

所以我决定搜索这个错误,它确实是从node_模块中的grunt spritesmith文件夹中产生的。。具体到文件中

  directories/myproject/node_modules/grunt-spritesmith/node_modules/spritesmith/node_modules/pixelsmith/node_modules/get-pixels/node_modules/pngjs/lib/bitmapper.js:
如果有此功能:

    function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) { // eslint-disable-line max-params
      var imageWidth = image.width;
      var imageHeight = image.height;
      var imagePass = image.index;
      for (var y = 0; y < imageHeight; y++) {
        for (var x = 0; x < imageWidth; x++) {
          var pxPos = getPxPos(x, y, imagePass);

          for (var i = 0; i < 4; i++) {
            var idx = pixelBppMap[bpp][i];
            if (i === data.length) {

              throw new Error('Ran out of data' +  JSON.stringify(image));
              // throw new Error('Ran out of data');

            }
            pxData[pxPos + i] = idx !== 0xff ? data[idx + rawPos] : 0xff;
          }
          rawPos += bpp; 
        }
      }
      return rawPos;
    }

这告诉我这是我的一张1px 1px图像。。原来是一个只有88字节的png导致了这个问题。。我不知道这会破坏它,但我把它留在这里,以防其他人遇到它。

在执行grunt任务后,你能编辑你的问题并复制/粘贴完整的错误输出吗。。。即将发布答案。
Fatal error: Ran out of data r{"width":1,"height":1}