Picture of Steven W
Automatic Image Minification
by Steven W - Tuesday, 14 March 2017, 5:35 PM
 

Hi everyone,

I'm trying to add image minification to the Adapt build process and have ran into some issues.

Here is what I've have done so far:

  • Installed grunt-contrib-imagemin and imagemin-mozjpeg (dependancy).
  • Created a Grunt task called "imagemin".
  • Created a Grunt task config called "imagemin".
  • Added "imagemin" to the last line of the build task. (we only want this when we build, not dev)

The build runs great, up to the point where it tries to run this new task. The error given is ">> No "imagemin" targets found. Warning: Task "imagemin" failed. Use --force to continue." 

Playing around with the paths doesn't change the result, however, adding all the code to the main gruntfile.js allows it to run correctly but causes all the other adapt tasks to no longer work (path issues).

What am I missing? Is there a different way to go about minifing the images on build? Since this forum doesn't have a good way to display code, the zip file attached has the files in question.

Thanks in advance for your help.

Picture of Matt Leathes
Re: Automatic Image Minification
by Matt Leathes - Wednesday, 15 March 2017, 3:27 PM
 

Hi Steve

If you jump onto the adapt-cli chat and start asking you might get a better response...

(Nothing wrong with asking here, it's just the kind of question that feels like it might be better dealt with on a chat)

Picture of Oliver Foster
Re: Automatic Image Minification
by Oliver Foster - Wednesday, 15 March 2017, 8:23 PM
 

Ok... um, it's clear that you haven't grasped Grunt configs and tasks yet, so I'll go easy on the copying and pasting from the grunt-config-imagemin readme.

I have no idea what your 'compile-course' task was in the build.js, so I removed it. I had to add back in all of the grunt tasks, configs and helpers from the adaptlearning version online (it would have been nice if you'd included them).

Your imagemin.js task doesn't need to register a default task. So you can remove the line:

grunt.registerTask('default', ['imagemin']);

 

Your imagemin.js config won't work because it doesn't follow the same pattern as the rest of the configs. It should read:

module.exports = function(grunt) {
//dependancy of imagemin
//var mozjpeg = require('imagemin-mozjpeg');
return {
compile: { // Task
options: { // Target options
optimizationLevel: 3,
svgoPlugins: [{ removeViewBox: false }],
//use: [mozjpeg()]
},
files: [{
expand: true, // Enable dynamic expansion
cwd: '<%= sourcedir %>course/en/images', // Src matches are relative to this path
src: ['**/*.{png,jpg,gif}'], // Actual patterns to match
dest: '<%= outputdir %>course/en/images' // Destination path prefix
}]
}
};
}

Notice that I've commented out all of the mozjpeg plugin bits as it all crashed on my system. Hopefully you can figure out why that plugin is broken (if it is on your machine). But this should at least get you mostly up and running for now.

Good luck.

 

Ollie.

Picture of Steven W
Re: Automatic Image Minification
by Steven W - Friday, 17 March 2017, 9:53 PM
 

I was able to get it working, thank you for your assistance. Have a good weekend!