Skip to content

Comment on Introducing Grunt

Comments

I'm not sure I understand the value of this project at all.

He says that maintaining a monolithic Makefile doesn't scale, but that seems unlikely considering how far BSD stretches Makefiles for it's ports system. Sure, Make has some rough edges, but I don't see how Javascript is possibly preferable for gluing together build processes.

The fundamental problem here is that "task based build system" is a silly idea. Make isn't a programming language, you don't define function names. Make is a dependency graph with files for nodes and command lines for edges. We already have a system for "tasks": stick things in ./script or add things to PATH!

By all means, make a metapackage for your test, lint, etc scripts, but define your concatonation like this:

    out/foo.js: banner src/foo.js
        cat $^ > $@
And generalize your minification using a pattern rule, here's ours:
    %.min.js: %.js
        $(yui) --type js --nomunge < $< > $@
Then add in a gzipping rule:
    %.gz: %
        gzip --best < $< > $@
You could trivially stick that sort of thing into `grunt.mk`...

And here's how you'd use that:

    include grunt.mk

    my-app.min.js.gz: my-app.min.js

    my-app.min.js: $(find src -name '*.js')
That said, sometimes it is nice to add some "tasks" for discoverability & encouraging their usage:
    include grunt.mk

    .PHONY: all lint test

    all: my-app.min.js.gz lint test

    my-app.min.js.gz: my-app.min.js

    my-app.min.js: $(find src -name '*.js')

    test:
        ./test/run

    lint:
        ./script/lint src
What if you want to run a subset of tests? Or lint with particular flags? Run a shell command like this one:
    $ grep test: -A1 Makefile
Then copy paste and edit the output!

Simpler is better.

You are right, all of this can be done via makefile ... assuming you know how to set up a makefile and take the time to do so. Part of the goal of grunt, as I understand it, is to make it so developers have fewer excuses for not doing this -- setting up a project of a certain type becomes a one-liner. To me, that feels a whole lot simpler than suggesting that developers create the makefile you propose. More often than not, such suggestions result in projects that have no makefile at all -- and thus no tests, no minification, no linting, etc. If grunt helps developers integrate those best practices more easily, that feels like a good thing to me.

I'm not sure why people are afraid of Makefiles. I know an incredible number of developers who view them as this scary black box. They are not a heavy weight thing which justify making excuses about not producing.

Here's what it takes to make a new Javascript project:

    mkdir project
    cd project
    touch foo.js bar.js
    echo -e 'project.js: foo.js bar.js\n\tcat $^ > $@' > Makefile
Unless you're jQuery, you don't need minification or GZipping because clients of your library already have their own. You don't need your own linting because you can trivially run `jshint project.js`.

If you find yourself running the same command in your shell a bunch of times, add it to your Makefile. It's that simple.

As someone who is not afraid of Makefiles (and has used them by default in past JavaScript-based projects), I welcome tools like Grunt to my projects. It fits in well with the types of "build" tasks I'm typically invoking in my JavaScript projects — and done so in a much simpler and abstracted syntax I prefer to work with.

Also, based on your comments, I think you and I have different definitions of "simple". :)

I'm using Rich Hickey's definition: http://www.infoq.com/presentations/Simple-Made-Easy

You might be using it to mean what he's defined as "easy".

I agree. I suck at coding Makefiles but I can't imagine using anything else and never bought Rakefile or Cakefile. I really don't want my build process to have dependencies.

(completely off topic)

for the rule:

       %.gz: %
wouldn't you need something like patsubst? Regardless of your response, could you share more info?

edit, that rule above only makes sense to me if the file name to be gzipped was passed to make. Is that correct? (I'm new to make)

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.