Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added cssmin and jsminify tasks

  • Loading branch information...
commit 38c59d0f0059682c528e45e47f8ee2ec309688f0 1 parent 8d77337
@davglass authored
Showing with 56 additions and 0 deletions.
  1. +13 −0 lib/tasks/cssmin.js
  2. +43 −0 lib/tasks/jsminify.js
View
13 lib/tasks/cssmin.js
@@ -0,0 +1,13 @@
+/*
+Copyright (c) 2012, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://yuilibrary.com/license/
+*/
+
+var cssmin = require('cssmin').cssmin;
+
+exports.cssmin = function (options, blob, done) {
+ var result = cssmin(blob.result);
+ done(null, new blob.constructor(result, blob));
+};
+
View
43 lib/tasks/jsminify.js
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
+ * Copyrights licensed under the New BSD License.
+ * See the accompanying LICENSE file for terms.
+ */
+var parser = require('uglify-js').parser,
+ uglify = require('uglify-js').uglify;
+
+/**
+ * Minify JS.
+ *
+ * @param options {Object} Task options.
+ * @param options.config {Object} Minify options.
+ * @param blob {Object} Incoming blob.
+ * @param done {Function} Callback on task completion.
+ */
+exports.jsminify = function (options, blob, done) {
+ options = options || {};
+
+ var config = options.config || {},
+ ast;
+
+ try {
+ ast = parser.parse(blob.result, config.semicolon || false);
+
+ if (config.mangle) {
+ ast = uglify.ast_mangle(ast, config);
+ }
+ if (config.squeeze) {
+ ast = uglify.ast_squeeze(ast, config);
+ }
+
+ done(null, new blob.constructor(uglify.gen_code(ast, config), blob));
+ } catch (e) {
+ if (options.callback) {
+ options.callback(e);
+ } else {
+ /*jslint nomen: true */
+ this._log(e);
+ }
+ done('Minify failed, ' + (blob.name || 'file') + ' unparseable');
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.