Frage

I've crossed the path of this npm module for grunt, github.com/ozanturgut/grunt-modules, which gives a way to make a real separation in Gruntfiles.js, making it more readable. But I'm wondering why it isn't more encouraged as a best practices. Any advices ?

War es hilfreich?

Lösung

Because it's not a best practice with Grunt. That library just adds another abstraction on top of tasks. Which means if you write a module per their specification, your module will ONLY work with their library. Thus further dividing the community.

It also creates a peer dependency to grunt-modules in addition to grunt. Peer dependencies are not easy to manage, especially if the peer author doesn't follow semver strictly. In most cases, being a peer isn't even necessary.

Using this.data is not recommended.

The Grunt team is moving towards a Node.js require() based approach. This will remove the peer dependency to grunt and allow Grunt tasks to be consumed by the entire node.js ecosystem. The Grunt team would like to encourage other users to try and follow suit.

So just using require() to add helpers to your Gruntfile is the best approach now for modularizing your Gruntfile. The approach of the next version of Grunt should greatly help users better modularize their gruntfiles.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top