Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added cssmin and jsminify tasks

  • Loading branch information...
commit 38c59d0f0059682c528e45e47f8ee2ec309688f0 1 parent 8d77337
Dav Glass authored

Showing 2 changed files with 56 additions and 0 deletions. Show diff stats Hide diff stats

  1. +13 0 lib/tasks/cssmin.js
  2. +43 0 lib/tasks/jsminify.js
13 lib/tasks/cssmin.js
... ... @@ -0,0 +1,13 @@
  1 +/*
  2 +Copyright (c) 2012, Yahoo! Inc. All rights reserved.
  3 +Code licensed under the BSD License:
  4 +http://yuilibrary.com/license/
  5 +*/
  6 +
  7 +var cssmin = require('cssmin').cssmin;
  8 +
  9 +exports.cssmin = function (options, blob, done) {
  10 + var result = cssmin(blob.result);
  11 + done(null, new blob.constructor(result, blob));
  12 +};
  13 +
43 lib/tasks/jsminify.js
... ... @@ -0,0 +1,43 @@
  1 +/*
  2 + * Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
  3 + * Copyrights licensed under the New BSD License.
  4 + * See the accompanying LICENSE file for terms.
  5 + */
  6 +var parser = require('uglify-js').parser,
  7 + uglify = require('uglify-js').uglify;
  8 +
  9 +/**
  10 + * Minify JS.
  11 + *
  12 + * @param options {Object} Task options.
  13 + * @param options.config {Object} Minify options.
  14 + * @param blob {Object} Incoming blob.
  15 + * @param done {Function} Callback on task completion.
  16 + */
  17 +exports.jsminify = function (options, blob, done) {
  18 + options = options || {};
  19 +
  20 + var config = options.config || {},
  21 + ast;
  22 +
  23 + try {
  24 + ast = parser.parse(blob.result, config.semicolon || false);
  25 +
  26 + if (config.mangle) {
  27 + ast = uglify.ast_mangle(ast, config);
  28 + }
  29 + if (config.squeeze) {
  30 + ast = uglify.ast_squeeze(ast, config);
  31 + }
  32 +
  33 + done(null, new blob.constructor(uglify.gen_code(ast, config), blob));
  34 + } catch (e) {
  35 + if (options.callback) {
  36 + options.callback(e);
  37 + } else {
  38 + /*jslint nomen: true */
  39 + this._log(e);
  40 + }
  41 + done('Minify failed, ' + (blob.name || 'file') + ' unparseable');
  42 + }
  43 +};

0 comments on commit 38c59d0

Please sign in to comment.
Something went wrong with that request. Please try again.