我按照我们亲爱的朋友 Chris Coyier 的教程Gruntfile.js
正确安装了 imagemin 。它可以编译,但我有两个奇怪的怪癖,基本上是两个问题......
问题一:
图像被创建双倍或三倍,这仅使用一个grunt
命令。下面你可以看到命令 grunt 之后创建的文件结构。想象一下,如果watch
经常这样做!我需要一个解决方案,因为如果可能的话,我希望这个功能是自动的,有什么帮助吗?
问题 2:
图像正确缩小,但我总是收到图像为空的错误,如下所示。有趣的是,那个图像已经被制作出来了。我想如果第一个问题得到解决,这个问题很可能会得到解决。在终端输出下方。
终端输出:
Running "imagemin:dynamic" (imagemin) task
✔ images/245x600.gif (saved 1.22 kB)
✔ images/300x500.gif (saved 1.38 kB)
✔ images/310x600.gif (saved 1.46 kB)
✔ images/400x600.gif (saved 1.85 kB)
✔ images/660x342.gif (saved 2.54 kB)
✔ images/940x487.gif (saved 3.69 kB)
✔ images/960x410.gif (saved 3.67 kB)
✔ images/build/build/245x600.gif (saved 1.22 kB)
✔ images/build/build/300x500.gif (saved 1.38 kB)
Warning: gifsicle: images/build/245x600.gif: empty file
这里问的是我的 Gruntfile.js 配置:
module.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// 2. Configuration for concatinating files goes here.
// Concatonate various files into one
concat: {
dist: {
src: [
'js/vendor/*.js', // All JS in the libs folder
'js/plugin.js', // All JS in the libs folder
'js/global.js' // This specific file
],
dest: 'js/build/production.js',
}
},
// Creates a minified version of the javascript files of the project
uglify: {
build: {
src: ['js/vendor/*.js', 'js/plugin.js', 'js/global.js'],
dest: 'js/build/production.min.js'
}
},
// Minifies automatically the images of the project
// imagemin: {
// dynamic: {
// files: [{
// expand: true,
// cwd: 'images/',
// src: ['**/*.{png,jpg,gif}'],
// dest: 'images/build/'
// }]
// }
// },
// Watches for changes done on the project and builds the commands if neccesary
watch: {
options: {
livereload: true,
},
scripts: {
files: ['js/*.js'],
tasks: ['concat', 'uglify'],
options: {
spawn: false,
},
},
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'css/build/style.css': 'sass/style.scss'
}
}
},
css: {
files: ['css/*.scss'],
tasks: ['sass'],
options: {
spawn: false,
}
}
}
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
// grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat', 'uglify', 'sass', 'compass', 'watch']);