当我尝试运行 Grunt imagemin 时抛出以下错误:
Running "imagemin:dynamic" (imagemin) task
Fatal error: Cannot read property 'contents' of undefined
这是我的 package.json 文件:
{
"name": "project1",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-imagemin": "^1.0.0",
"grunt-contrib-uglify": "^0.11.0",
"imagemin" : "4.0.0"
}
}
这是我的 Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
build: {
src: 'views/js/src/main.js',
dest: 'views/js/build/main.js'
}
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'views/images/src/',
src: ['**/*.{png,jpg,gif}'],
dest: 'views/images/build/'
}]
}
}
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['uglify', 'imagemin']);
};
问题是 flagged and evidently resolved在先前版本的 imagemin 中。但商定的解决方案是将 grunt-contrib-imagemin 更新为 1.0.0 版,将 imagemin 更新为 4.0.0 版,我已经完成了,但仍然无法正常工作。
最佳答案
只需将 gurnt-contrib-imagemin 更新到 1.0.0 或最新版本,您可能使用的旧版本可能是 0.9.x
关于javascript - 咕噜 imagemin 错误 : Cannot read property 'contents' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34755753/