Skip to content

Commit

Permalink
Allowing an environment variable of MINIFY=false to disable minificat…
Browse files Browse the repository at this point in the history
…ion of the build:browser cake task.
  • Loading branch information
jashkenas committed Jan 15, 2011
1 parent df872b8 commit 7ae284f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser',
#{fs.readFileSync "lib/#{name}.js"}
};
"""
{parser, uglify} = require 'uglify-js'
ast = parser.parse """
code = """
this.CoffeeScript = function() {
function require(path){ return require[path]; }
#{code}
return require['./coffee-script']
}()
"""
code = uglify.gen_code uglify.ast_squeeze uglify.ast_mangle ast, extra: yes
unless process.env.MINIFY is 'false'
{parser, uglify} = require 'uglify-js'
code = uglify.gen_code uglify.ast_squeeze uglify.ast_mangle parser.parse code
fs.writeFileSync 'extras/coffee-script.js', header + '\n' + code
console.log "built ... running browser tests:"
invoke 'test:browser'
Expand Down

4 comments on commit 7ae284f

@michaelficarra
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, this is pretty ugly. Wouldn't it be better if there was a separate cake task for minifying the browser build and this task invoked that one? Then we could just implement command-line options like in rake tasks (scroll to "Tasks with Arguments" section) to specify when we want to skip the minification.

Or, if we didn't want to implement argument-passing, we could just create a build task, a minification task, and a build_and_minify task, which just runs the other two successively. Both of these solutions seem more elegant to me than the one implemented in this commit.

@jashkenas
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree ... environment variables are often how arguments are passed into shell scripts -- but I'd also be happy to have an implementation of tasks-that-take-arguments, as long as we can make it nicer than rake arguments (which are pretty awful).

@michaelficarra
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that rake arguments aren't the best, so I'd be in favor of an implementation of the second method I proposed. Are you in agreement, jashkenas?

@jashkenas
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all. Deciding whether to minify or not is very much an option of the build:browser task -- we really don't need to litter the task list with variants of it. I think that environment variables are fine, as are arguments, if we have a nice implementation.

Please sign in to comment.