UNPKG

ng-annotate-uglify-js-brunch

Version:

Adds ng-annotate AND Uglify minifying support to brunch.

68 lines (57 loc) 2.04 kB
// Generated by CoffeeScript 1.9.1 var NgAnnotateUglifyMinifier, clone, ngAnnotate, sysPath, uglify, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; sysPath = require('path'); uglify = require('uglify-js'); ngAnnotate = require('ng-annotate'); clone = function(obj) { var copied, key, val; if ((obj == null) || typeof obj !== 'object') { return obj; } copied = new obj.constructor(); for (key in obj) { val = obj[key]; copied[key] = clone(val); } return copied; }; module.exports = NgAnnotateUglifyMinifier = (function() { NgAnnotateUglifyMinifier.prototype.brunchPlugin = true; NgAnnotateUglifyMinifier.prototype.type = 'javascript'; function NgAnnotateUglifyMinifier(config) { var ref, ref1, ref2; this.config = config; this.optimize = bind(this.optimize, this); this.options = (clone((ref = this.config) != null ? (ref1 = ref.plugins) != null ? ref1.uglify : void 0 : void 0)) || {}; this.options.fromString = true; this.options.sourceMaps = (ref2 = this.config) != null ? ref2.sourceMaps : void 0; } NgAnnotateUglifyMinifier.prototype.optimize = function(data, path, callback) { var annotated, err, error, optimized, options, result; options = this.options; options.outSourceMap = options.sourceMaps ? path + ".map" : void 0; try { annotated = ngAnnotate(data, { add: true }); if (annotated.errors) { throw new Error(annotated.errors.join("\n")); } return optimized = uglify.minify(annotated.src, options); } catch (_error) { err = _error; return error = "ng-annotate or JS minify failed on " + path + ": " + err; } finally { result = optimized && options.sourceMaps ? { data: optimized.code, map: optimized.map } : { data: optimized.code }; result.data = result.data.replace(/\n\/\/# sourceMappingURL=\S+$/, ''); callback(error, result || data); } }; return NgAnnotateUglifyMinifier; })();