Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
Created October 24, 2012 19:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sindresorhus/3948386 to your computer and use it in GitHub Desktop.
Save sindresorhus/3948386 to your computer and use it in GitHub Desktop.
grunt-contrib task proposal

grunt-contrib task proposal

We intend extract the tasks included in Yeoman to make the project more modular and be a good internet citizen. We've already done so with the Compass task.

I've added some tasks that might be fitted for grunt-contrib.

grunt-contrib-img

Optimizing images is something most projects need. I think it's important grunt-contrib has a simple and opinionated task for this.

When we created the Yeoman img task I researched the best tools out there. We didn't want to complicate the setup with a lot of different minifiers and ended up with OptiPNG and jpegtran from the libjpeg-turbo package, both working cross OS, actively developed and super fast.

There already exist a grunt plugin for optimizing images, but it's too flexible and I would like something that is super simple to set up and use without having to change a single setting, of course you can if you want.

This task would require dependency on both optipng binary and jpegtran, but I'm going to work around that by creating a couple of wrapper node modules embedding those. This would mean it would be completely transparent for the enduser.

OptiPNG

This project is based on PNGCrush. According to the author, it's running faster because all trials are performed in memory. It also includes parts of PNGRewrite code for some images reductions. OptiPNG is used by a lot of optimizers, including onlines services as SmushIt.

jpegtran (libjpeg-turbo)

libjpeg-turbo is a derivative of libjpeg that uses SIMD instructions (MMX, SSE2, NEON) to accelerate baseline JPEG compression and decompression on x86, x86-64, and ARM systems. On such systems, libjpeg-turbo is generally 2-4x as fast as the unmodified version of libjpeg, all else being equal.

grunt-contrib-minhtml

Not sure if it's useful enough to be included in grunt-contrib, but might be useful. Thoughts?

https://github.com/yeoman/yeoman/blob/master/cli/tasks/html.js https://github.com/kangax/html-minifier

Prior art: https://github.com/jney/grunt-htmlcompressor But requires Java.

grunt-contrib-livereload

Yeomans livereload task is to specialized to be used, but I was just wondering if this is something that could be useful to have in contrib?

Prior art: https://github.com/webxl/grunt-reload

@cowboy
Copy link

cowboy commented Oct 24, 2012

Is this a complete list, or are there more possible plugins?

@sindresorhus
Copy link
Author

Yes. There are more, but they either already exists or not considered useful enough for grunt contrib.

One possible more is our usemin task, which basically uses HTML comments block to infer scripts and combine them: https://github.com/yeoman/yeoman/blob/master/cli/tasks/usemin.js

@cowboy
Copy link

cowboy commented Oct 24, 2012

Does grunt-contrib-img have non-npm dependencies that have to be installed separately?

@sindresorhus
Copy link
Author

@cowboy

Just added:

This task would require dependency on both optipng binary and jpegtran, but I'm going to work around that by creating a couple of wrapper node modules embedding those. This would mean it would be completely transparent for the enduser.

@tkellen
Copy link

tkellen commented Oct 24, 2012

Usemin doesn't seem quite generic enough, but I like the rest. I think we should talk to the author's of the existing tasks to see if they'd be willing to participate in contrib first, though. Are you planning on having a yeoman-* series of tasks Sindre?

@sindresorhus
Copy link
Author

I think we should talk to the author's of the existing tasks to see if they'd be willing to participate in contrib first, though

The grunt-imagine task has a completely different goal. It wants to be a generic wrapper for every minifier tool out there, quite the opposite of what I want. So I don't see point of trying to smash them together.

grunt-contrib-minhtml: Same as above. I think they can coexist since they are somewhat different. This one is about speed and no dependencies, while the grunt-htmlcompressor has a lot more options and compresses better, but is slower and requires Java.

On the livereload part we might be able to convince the creator of Livereload to help us out: yeoman/yeoman#182

@tkellen Thoughts?

Are you planning on having a yeoman-* series of tasks Sindre?

We haven't decided yet exactly how we want to do it. A couple of tasks are going being rewritten and upstreamed to contrib, some just extracted and published on their own as generic tasks, and some are highly specialized to yeoman and will most likely not be useful to anyone else.

@tkellen
Copy link

tkellen commented Oct 24, 2012

I try to adhere to the unix philsophy of do one thing and do it well as much as possible (hence the grunt org having like 33 individual repos). I didn't investigate the prior art plugins closely, so thanks for the clarifications! I'm on board for all three of these. Let me chat with @cowboy to make sure he agrees. Assuming he does, I'll get the repos scaffolded for you right away.

RE: yeoman's super-specific tasks, there is nothing preventing you from bundling more than one task in a single npm package for local installation, if you want to make it a suite. If I were in your position, though, I'd go the contrib route. It is a bit more overhead to develop but I've found it to be a big win from a flexibility and community contribution standpoint.

@sindresorhus
Copy link
Author

Assuming he does, I'll get the repos scaffolded for you right away.

Yay.

I'd go the contrib route. It is a bit more overhead to develop but I've found it to be a big win from a flexibility and community contribution standpoint.

They are super-specific tasks for a reason, trust me if I see a way to make them generic enough to be published, I surely will :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment