UNPKG

asset-rack

Version:

Static Web Framework for Nodejs

69 lines (56 loc) 2.13 kB
// Generated by CoffeeScript 1.6.3 (function() { var Asset, browserify, fs, pathutil, uglify, _ref, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; fs = require('fs'); pathutil = require('path'); browserify = require('browserify'); uglify = require('uglify-js'); Asset = require('../index').Asset; exports.BrowserifyAsset = (function(_super) { __extends(BrowserifyAsset, _super); function BrowserifyAsset() { _ref = BrowserifyAsset.__super__.constructor.apply(this, arguments); return _ref; } BrowserifyAsset.prototype.mimetype = 'text/javascript'; BrowserifyAsset.prototype.create = function(options) { var agent, handler, uncompressed, _i, _len, _ref1; this.filename = options.filename; this.toWatch = pathutil.dirname(pathutil.resolve(this.filename)); this.require = options.require; this.debug = options.debug || false; this.compress = options.compress; if (this.compress == null) { this.compress = false; } this.extensionHandlers = options.extensionHandlers || []; agent = browserify({ watch: false, debug: this.debug }); _ref1 = this.extensionHandlers; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { handler = _ref1[_i]; agent.register(handler.ext, handler.handler); } agent.addEntry(this.filename); if (this.require) { agent.require(this.require); } if (this.compress === true) { uncompressed = agent.bundle(); this.contents = uglify.minify(uncompressed, { fromString: true }).code; return this.emit('created'); } else { return this.emit('created', { contents: agent.bundle() }); } }; return BrowserifyAsset; })(Asset); }).call(this);