Skip to content
This repository has been archived by the owner on May 25, 2019. It is now read-only.

Use jit-grunt instead of grunt-load-tasks? #540

Closed
nickautomatic opened this issue May 5, 2015 · 9 comments
Closed

Use jit-grunt instead of grunt-load-tasks? #540

nickautomatic opened this issue May 5, 2015 · 9 comments

Comments

@nickautomatic
Copy link

This has previously been discussed but was rejected because at the time it was felt that jit-grunt was harder to configure. However, since then jit-grunt seems to have come along a bit, and it is now arguably no more complex to configure, while leading to very significant speed improvements. I wonder if it would be worth another look?

The advantage of grunt-load-tasks is that because it loads all plugins (named "grunt-") by default, it works ok where task names don't match a plugin (eg. "useminPrepare" --> "grunt-usemin"). However, it doesn't load plugins with names like "grunt-contrib-" or just "*" by default.

jit-grunt maps to all three of the above patterns by default, so will find some plugins (eg. "assemble") that grunt-load-tasks doesn't out of the box. However, it does require configuration where the task name doesn't match a plugin (eg. useminPrepare).

Speaking as a relative beginner with Grunt / node.js myself, I found it difficult to figure out how to configure load-grunt-tasks to work with a plugin whose name doesn't match load-grunt-task's default mapping. If generator-webapp used jit-grunt you'd have a working example -- commented, even -- in the default Gruntfile that would make it clear how to add new plugins / tasks. Something like:

// Auto-load grunt tasks as they're needed:
require('jit-grunt')(grunt, {
  // Tasks whose names match the name of an installed plugin 
  // (eg. 'task', 'grunt-task', 'grunt-contrib-task') 
  // will be found and loaded automatically.
  // 
  // For tasks whose names don't match the name of a plugin
  // tell Grunt which plugin to load here:
  useminPrepare: 'grunt-usemin'
});

...admittedly a little more complex as a default, but by being explicit rather than implicit, probably not actually worse (and arguably even perhaps better) for beginners. Anyway, just a thought / suggestion. For me it doesn't feel like there's that much in it in terms of complexity, and jit-grunt's significant speed improvements certainly make working with grunt more pleasant, on my machine anyway.

(See also discussion here)

@eddiemonge
Copy link
Member

Out of curiosity, which plugin name doesn't match?

@sindresorhus
Copy link
Member

However, it doesn't load plugins with names like "grunt-contrib-*"

That's incorrect. "grunt-*" matches grunt-contrib- too.

or just "*" by default

No good reason to do that.

I found it difficult to figure out how to configure load-grunt-tasks to work with a plugin whose name doesn't match load-grunt-task's default mapping

Why? And how does jit-grunt make that simpler?

jit-grunt's significant speed improvements certainly make working with grunt more pleasant, on my machine anyway.

Where are the numbers? Last time we had this discussion the numbers where negligible and variable.

@marian-r
Copy link
Contributor

+1 for jit-grunt. I started using it today and loading of tasks is faster.

Build task with load-grunt-tasks:

load-grunt-tasks2

Build task with jit-grunt:

jit-grunt

The performance gain is even more significant when running a task after a long break. Loading of tasks with load-grunt-tasks can be such slow (for the same task as above):

load-grunt-tasks

You should include jit-grunt in this generator as some users are requesting it (yeoman/generator-webapp#278, yeoman/yeoman#1382) and loving it (gruntjs/grunt#975). What do you think?

@nickautomatic
Copy link
Author

Firstly, excuse my slowness replying.

@sindresorhus: Ok, good point, sorry - I was wrong about grunt-load-task's plugin matching. To be honest, though, I probably overemphasised that aspect - it happens that I struggled a bit to get assemble working with grunt-load-tasks, when it seems it would have worked out of the box with jit-grunt. The main advantage of jit-grunt really is the significant speed improvement; my point in raising the configuration issue was that last time this was discussed it seems that jit-grunt was rejected as being potentially more difficult to configure than grunt-load-tasks. My point really was that at this point there's no very clear difference in complexity between them, so it might be worth reconsidering jit-grunt on the merits of its speed.

As for speed, with every project I've compared them on, jit-grunt has been significantly faster. If you're comparing them, bear in mind that the difference is likely to be proportionally greater on, eg. watch tasks than on build tasks, since jit-grunt saves time by only loading tasks as they're needed (so when you, say, edit a watched Javascript file, it only load the JS-related tasks). For "build"-type tasks, I'd expect there to be less difference (since jit-grunt will have to load most or all tasks anyway), but even there my experience has generally been in line with @marian-r's. For watch tasks, I've found jit-grunt is consistently a couple of seconds faster - very noticeable when live-reloading.

@nickautomatic
Copy link
Author

...In summary, my point was since:
a) jit-grunt is consistently faster; and
b) nowadays (as far as I can see) it's no longer any more difficult to configure,
...it might be worth reconsidering the earlier decision not to use it.

@marian-r
Copy link
Contributor

Agree with @nickautomatic

  • watch tasks start immediately with jit-grunt, comparing to seconds spend on loading tasks with load-grunt-tasks
  • configuration is not difficult and there is a nice message if any configuration is required

@silvenon
Copy link
Member

We would appreciate a PR. Otherwise we'll implement this when we have time.

@marian-r
Copy link
Contributor

Here it is #554 :) And I would recommend using jit-grunt also in other generators. Should I repeat this PR?

@silvenon
Copy link
Member

Yes, you can, it's clearly faster.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants